Lines Matching +full:basic +full:- +full:ftp
1 :mod:`urllib.request` --- Extensible library for opening URLs
13 --------------
16 opening URLs (mostly HTTP) in a complex world --- basic and digest
22 is recommended for a higher-level HTTP client interface.
24 .. include:: ../includes/wasm-notavail.rst
44 only works for HTTP, HTTPS and FTP connections.
66 attribute --- the reason phrase returned by server --- instead of
70 For FTP, file, and data URLs and requests explicitly handled by legacy
91 .. audit-event:: urllib.Request fullurl,data,headers,method urllib.request.urlopen
164 Convert the path component *path* from a percent-encoded URL to the local syntax for a
200 types include bytes, file-like objects, and iterables of bytes-like objects.
201 If no ``Content-Length`` nor ``Transfer-Encoding`` header field
203 to the type of *data*. ``Content-Length`` will be used to send
204 bytes objects, while ``Transfer-Encoding: chunked`` as specified in
208 standard :mimetype:`application/x-www-form-urlencoded` format. The
210 of 2-tuples and returns an ASCII string in this format. It should
215 This is often used to "spoof" the ``User-Agent`` header value, which is
216 used by a browser to identify itself -- some HTTP servers only
221 ``"Python-urllib/2.6"`` (on Python 2.6).
224 An appropriate ``Content-Type`` header should be included if the *data*
226 is not None, ``Content-Type: application/x-www-form-urlencoded`` will
230 of third-party HTTP cookies:
232 *origin_req_host* should be the request-host of the origin
237 this should be the request-host of the request for the page
260 a 100-continue expectation in the library.
269 Do not raise an error if the ``Content-Length`` has not been
281 This is the base class for all registered handlers --- and handles only the
314 which shouldn't be reached via proxy; if set, it should be a comma-separated
326 Keep a database of ``(realm, uri) -> (user, password)`` mappings.
331 Keep a database of ``(realm, uri) -> (user, password)`` mappings. A realm of
332 ``None`` is considered a catch-all realm, which is searched if no other realm
339 database of ``uri -> is_authenticated`` mappings. Can be used by a
351 :ref:`http-password-mgr` for information on the interface that must be
354 :ref:`http-password-mgr-with-prior-auth`), then the handler will use the
359 received the request is re-sent with the authentication credentials. If
362 the URI or any of its super-URIs will automatically include the
373 section :ref:`http-password-mgr` for information on the interface that must
382 :ref:`http-password-mgr` for information on the interface that must be
391 :ref:`http-password-mgr` for information on the interface that must be
399 section :ref:`http-password-mgr` for information on the interface that must
400 be supported. When both Digest Authentication Handler and Basic
403 to Basic Authentication handler to Handle. This Handler method will raise a
405 Digest or Basic.
416 :ref:`http-password-mgr` for information on the interface that must be
446 Open FTP URLs.
451 Open FTP URLs, keeping a cache of open FTP connections to minimize delays.
456 A catch-all class to handle unknown URLs.
464 .. _request-objects:
467 ---------------
507 Changing value of :attr:`Request.data` now deletes "Content-Length"
550 meaning when used more than once have a (header-specific) way of gaining the
606 .. _opener-director-objects:
609 ----------------------
624 * :meth:`<protocol>_open` --- signal that the handler knows how to open *protocol*
629 * :meth:`http_error_\<type\>` --- signal that the handler knows how to handle HTTP
634 * :meth:`<protocol>_error` --- signal that the handler knows how to handle errors
635 from (non-\ ``http``) *protocol*.
637 * :meth:`<protocol>_request` --- signal that the handler knows how to pre-process
642 * :meth:`<protocol>_response` --- signal that the handler knows how to
643 post-process *protocol* responses.
661 HTTP, HTTPS and FTP connections.
680 method called to pre-process the request.
683 the request. This stage ends when a handler either returns a non-\ :const:`None`
698 method called to post-process the response.
701 .. _base-handler-objects:
704 -------------------
742 :class:`OpenerDirector`. It should return a file-like object as described in
748 This method will be called before any protocol-specific open method.
776 override it if they intend to provide a catch-all for otherwise unhandled HTTP
780 *req* will be a :class:`Request` object, *fp* will be a file-like object with
781 the HTTP error body, *code* will be the three-digit code of the error, *msg*
782 will be the user-visible explanation of the code and *hdrs* will be a mapping
792 *nnn* should be a three-digit HTTP error code. This method is also not defined
807 define it if they want to pre-process requests of the given protocol.
819 define it if they want to post-process responses of the given protocol.
828 .. _http-redirect-handler:
831 ---------------------------
841 HTTPS or FTP URL.
895 .. _http-cookie-processor:
898 ---------------------------
907 .. _proxy-handler:
910 --------------------
923 .. _http-password-mgr:
926 -----------------------
936 authentication tokens when authentication for *realm* and a super-URI of any of
949 .. _http-password-mgr-with-prior-auth:
952 ------------------------------------
985 .. _abstract-basic-auth-handler:
988 --------------------------------
993 Handle an authentication request by getting a user/password pair, and re-trying
1005 .. _http-basic-auth-handler:
1008 ----------------------------
1016 .. _proxy-basic-auth-handler:
1019 -----------------------------
1027 .. _abstract-digest-auth-handler:
1030 ---------------------------------
1041 .. _http-digest-auth-handler:
1044 -----------------------------
1052 .. _proxy-digest-auth-handler:
1055 ------------------------------
1063 .. _http-handler-objects:
1066 -------------------
1075 .. _https-handler-objects:
1078 --------------------
1087 .. _file-handler-objects:
1090 -------------------
1103 .. _data-handler-objects:
1106 -------------------
1118 .. _ftp-handler-objects:
1121 ------------------
1126 Open the FTP file indicated by *req*. The login is always done with empty
1130 .. _cacheftp-handler-objects:
1133 -----------------------
1149 .. _unknown-handler-objects:
1152 ----------------------
1160 .. _http-error-processor-objects:
1163 --------------------------
1171 For non-200 error codes, this simply passes the job on to the
1184 .. _urllib-request-examples:
1187 --------
1190 :ref:`urllib-howto`.
1199 b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1200 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html
1202 <meta http-equiv="content-type" content="text/html; charset=utf-8" />\n
1211 The following W3C document, https://www.w3.org/International/O-charset\ , lists
1215 As the python.org website uses *utf-8* encoding as specified in its meta tag, we
1219 ... print(f.read(100).decode('utf-8'))
1221 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1229 >>> print(f.read(100).decode('utf-8'))
1230 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1233 In the following example, we are sending a data-stream to the stdin of a CGI
1238 >>> req = urllib.request.Request(url='https://localhost/cgi-bin/test.cgi',
1241 ... print(f.read().decode('utf-8'))
1250 print('Content-type: text/plain\n\nGot Data: "%s"' % data)
1262 Use of Basic HTTP Authentication::
1265 # Create an OpenerDirector with support for Basic HTTP Authentication...
1268 uri='https://mahler:8092/site-updates.py',
1301 # Customize the default User-Agent header value:
1302 req.add_header('User-Agent', 'urllib-example/0.1 (Contact: . . .)')
1305 :class:`OpenerDirector` automatically adds a :mailheader:`User-Agent` header to
1310 opener.addheaders = [('User-agent', 'Mozilla/5.0')]
1313 Also, remember that a few standard headers (:mailheader:`Content-Length`,
1314 :mailheader:`Content-Type` and :mailheader:`Host`)
1318 .. _urllib-examples:
1326 >>> url = "http://www.musi-cal.com/cgi-bin/query?%s" % params
1328 ... print(f.read().decode('utf-8'))
1339 ... print(f.read().decode('utf-8'))
1349 ... f.read().decode('utf-8')
1357 ... f.read().decode('utf-8')
1362 ----------------
1383 third argument may be ``-1`` on older FTP servers which do not return a file
1396 :mimetype:`application/x-www-form-urlencoded` format; see the
1401 size reported by a *Content-Length* header). This can occur, for example, when
1404 The *Content-Length* is treated as a lower bound: if there's more data to read,
1411 If no *Content-Length* header was supplied, urlretrieve can not check the size
1425 objects using schemes other than :file:`http:`, :file:`ftp:`, or :file:`file:`,
1428 By default, the :class:`URLopener` class sends a :mailheader:`User-Agent` header
1430 Applications can define their own :mailheader:`User-Agent` header by subclassing
1469 local file, the input filename is returned. If the URL is non-local and
1474 …(-1 if unknown). It will be called once at the start and after each chunk of data is read from the
1480 :mimetype:`application/x-www-form-urlencoded` format; see the
1499 the actual URL. For 401 response codes (authentication required), basic HTTP
1517 When performing basic authentication, a :class:`FancyURLopener` instance calls
1529 password)``, which can be used for basic authentication.
1537 ----------------------------------
1541 pair: FTP; protocol
1544 1.0), FTP, local files, and data URLs.
1554 file can't be opened, the URL is re-interpreted using the FTP protocol. This
1569 header, which can be inspected by looking at the :mailheader:`Content-Type`
1573 .. index:: single: FTP
1575 * The code handling the FTP protocol cannot differentiate between a file and a
1583 you try to fetch a file whose read permissions make it inaccessible; the FTP
1585 listing for the unreadable file. If fine-grained control is needed, consider
1591 :mod:`urllib.response` --- Response classes used by urllib
1598 minimal file-like interface, including ``read()`` and ``readline()``.