PyDocs

Nav

Internet Protocols and Support

Request

urllib.request

class (source) not WASI
  • Request(url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None)
This class is an abstraction of a URL request.
Changed in 3.3, 3.4, 3.6
  • 3.3: Request.method argument is added to the Request class.
  • 3.4: Default Request.method may be indicated at the class level.
  • 3.6: Do not raise an error if the Content-Length has not been provided and data is neither None nor a bytes object. Fall back to use chunked transfer encoding instead.
Members of Request

a

add_header
Add another header to the request.
add_unredirected_header
Add a header that will not be added to a redirected request.

d

data
The entity body for the request, or None if not specified.

f

full_url
The original URL passed to the constructor.

g

get_full_url
Return the URL given in the constructor.
get_header
Return the value of the given header.
get_method
Return a string indicating the HTTP request method.

h

has_header
Return whether the instance has the named header (checks both regular and unredirected).
header_items
Return a list of tuples (header_name, header_value) of the Request headers.
host
The URI authority, typically a host, but may also contain a port separated by a colon.

m

method
The HTTP request method to use.

o

origin_req_host
The original host for the request, without port.

r

remove_header
Remove named header from the request instance (both from regular and unredirected headers).

s

selector
The URI path.
set_proxy
Prepare the request by connecting to a proxy server.

t

type
The URI scheme.

u

unverifiable
boolean, indicates whether the request is unverifiable as defined by RFC 2965.
1 Example
>>> import urllib.request
>>> req = urllib.request.Request(url='https://localhost/cgi-bin/test.cgi',
...                       data=b'This data is passed to stdin of the CGI')
>>> with urllib.request.urlopen(req) as f:
...     print(f.read().decode('utf-8'))
...
Got Data: "This data is passed to stdin of the CGI"
from the Python docs
See Also
No see-alsos for urllib.request/Request
0 Notes
No notes for Request