Tools, FAQ, Tutorials:
Sending an HTTP Request with 'urllib.request'
How to send an HTTP request using the "urllib.request" module?
✍: FYIcenter.com
To send an HTTP request to the Internet, you can use
the urllib.request.urlopen() function as described below:
r = urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None) where: url can be a URL string or Request object data is request body as a binary string.
All urlopen() returns an http.client.HTTPResponse object. You can use its read() function to access the response body.
Here is a Python example on how to send a GET request and print the response body:
>>> import urllib >>> r = urllib.request.urlopen('http://httpbin.org/get') >>> b = r.read() >>> print(b) b'{\n "args": {}, \n "headers": {\n "Accept-Encoding": "identity", \n "Connection": "close", \n "Host": "httpbin.org", \n "User-Agent": "Python-urllib/3.6"\n }, \n "url": "http://httpbin.org/get"\n}\n'
⇒ http.client.HTTPResponse Objects
⇐ What Is Python Module 'urllib'
2018-09-24, 1383👍, 0💬
Popular Posts:
How to login to Azure API Management Publisher Portal 2017 version? If you have given access permiss...
How to create a new API on the Publisher Dashboard of an Azure API Management Service? If you are ne...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
How to create Hello-2.0.epub with WinRAR? I have all required files to create Hello-2.0.epub. To cre...