Python | How fix the SSL Certificate_verify_failed Error?
With PIP you can update your SSL certificate directory with the following piece of code: pip install –upgrade certifi
With PIP you can update your SSL certificate directory with the following piece of code: pip install –upgrade certifi
sudo apt-get build-dep python-psycopg2 pip install psycopg2-binary
from pathlib import Path import requests filename = Path(‘myfile.pdf’) headers = {‘User-Agent’: ‘Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36’} url = ‘http://example.com/myfile.pdf’ response = requests.get(url, headers=headers) filename.write_bytes(response.content)
Let’s take a list like this as an example: numbers = [i for i in xrange(1,11)] + [i for i in xrange(1,8)] To remove duplicates in the numbers list you could use this code: uk_numbers…
MongoDB: Search for documents without a property and add it with pymongo. from pymongo import MongoClient client = MongoClient(“myconnectionstring”) db = client.mydb cursor = db.mydocs.find({“myproperty”: None}) for document in cursor: print(document[“_id”]) db.mydocs.update({“_id”: document[“_id”]}, {“$set”: {“myproperty”:…
In this post i extend an example found on stackoverflow.com, here’s how to launch two simultaneous threads and stop them after 5 seconds. import threading import time def doit(arg): t = threading.currentThread() while getattr(t, “do_run”,…
If you simply want to compile a file or group of python files from the terminal, the py_compile module can run as a script as follows: python -m py_compile file1.py file2.py file3.py Actually, to run…
Python provides the urllib2 module that helps us in HTTP requests by defining functions and classes for redirecting, cookies, authentication and more. Here’s an example to take the content of a page and store it…