Appearance
urllib
TIP
For HTTPS, use the bundled requests package, or create an SSL context with the bundled certifi CA bundle. Do not use ssl.SSLContext() with its default settings: it disables certificate verification.
GET Method
HTTP:
python
from urllib.request import urlopen
from catscript import sys
if __name__ == "__main__":
response = urlopen("http://httpbin.org/get", timeout=10)
sys.log(response.status)
data = response.read()
sys.log(data)HTTPS:
python
import ssl
import certifi
from urllib.request import urlopen
from catscript import sys
if __name__ == "__main__":
context = ssl.create_default_context(cafile=certifi.where())
response = urlopen("https://httpbin.org/get", context=context, timeout=10)
sys.log(response.status)
data = response.read()
sys.log(data)POST Method
HTTP:
python
import urllib.parse
from urllib.request import urlopen
from catscript import sys
if __name__ == "__main__":
data = urllib.parse.urlencode({"name": "test"}).encode()
response = urlopen("http://httpbin.org/post", data=data, timeout=10)
sys.log(response.status)
sys.log(response.read())HTTPS:
python
import ssl
import urllib.parse
import certifi
from urllib.request import urlopen
from catscript import sys
if __name__ == "__main__":
context = ssl.create_default_context(cafile=certifi.where())
data = urllib.parse.urlencode({"name": "test"}).encode()
response = urlopen("https://httpbin.org/post", data=data, context=context, timeout=10)
sys.log(response.status)
sys.log(response.read())