Recent Tips (Part 2)

More quick notes that are too small for full posts.

Disable SSL validation in Twisted Agent

1
2
from twisted.internet import _sslverify
_sslverify.platformTrust = lambda: None

https://stackoverflow.com/questions/39704932/disable-ssl-certificate-check-twisted-agents

macOS ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED]

Run Install Certificates.command under Applications/Python 3.6.

Find which package provides a file on CentOS

yum whatprovides */libGL.so.1

Insert text at the top of QPlainTextEdit

1
2
3
4
cursor = self.textedit.textCursor()
cursor.setPosition(0)
self.textedit.setTextCursor(cursor)
self.textedit.insertPlainText(...)

Get all non-private attributes from an object

1
2
3
4
5
def get_obj_dict(obj):
return {
k: v for k, v in obj.__dict__.items()
if not (k.startswith('_') or isinstance(v, (type, types.ModuleType)))
}

MongoDB dotted keys error

Before MongoDB 3.6, field names cannot contain .. Attempting to insert one raises pymongo writeerror : the dotted field is not valid for storage. Upgrade to ≥3.6 or rename the key.
https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names