|
11 | 11 | Handlers needed to open the requested URL. For example, the
|
12 | 12 | HTTPHandler performs HTTP GET and POST requests and deals with
|
13 | 13 | non-error returns. The HTTPRedirectHandler automatically deals with
|
14 |
| -HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler |
15 |
| -deals with digest authentication. |
| 14 | +HTTP 301, 302, 303, 307 and 308 redirect errors, and the |
| 15 | +HTTPDigestAuthHandler deals with digest authentication. |
16 | 16 |
|
17 | 17 | urlopen(url, data=None) -- Basic usage is the same as original
|
18 | 18 | urllib. pass the url and optionally data to post to an HTTP URL, and
|
@@ -661,7 +661,7 @@ def redirect_request(self, req, fp, code, msg, headers, newurl):
|
661 | 661 | but another Handler might.
|
662 | 662 | """
|
663 | 663 | m = req.get_method()
|
664 |
| - if (not (code in (301, 302, 303, 307) and m in ("GET", "HEAD") |
| 664 | + if (not (code in (301, 302, 303, 307, 308) and m in ("GET", "HEAD") |
665 | 665 | or code in (301, 302, 303) and m == "POST")):
|
666 | 666 | raise HTTPError(req.full_url, code, msg, headers, fp)
|
667 | 667 |
|
@@ -748,7 +748,7 @@ def http_error_302(self, req, fp, code, msg, headers):
|
748 | 748 |
|
749 | 749 | return self.parent.open(new, timeout=req.timeout)
|
750 | 750 |
|
751 |
| - http_error_301 = http_error_303 = http_error_307 = http_error_302 |
| 751 | + http_error_301 = http_error_303 = http_error_307 = http_error_308 = http_error_302 |
752 | 752 |
|
753 | 753 | inf_msg = "The HTTP server returned a redirect error that would " \
|
754 | 754 | "lead to an infinite loop.\n" \
|
@@ -2211,6 +2211,13 @@ def http_error_307(self, url, fp, errcode, errmsg, headers, data=None):
|
2211 | 2211 | else:
|
2212 | 2212 | return self.http_error_default(url, fp, errcode, errmsg, headers)
|
2213 | 2213 |
|
| 2214 | + def http_error_308(self, url, fp, errcode, errmsg, headers, data=None): |
| 2215 | + """Error 308 -- relocated, but turn POST into error.""" |
| 2216 | + if data is None: |
| 2217 | + return self.http_error_301(url, fp, errcode, errmsg, headers, data) |
| 2218 | + else: |
| 2219 | + return self.http_error_default(url, fp, errcode, errmsg, headers) |
| 2220 | + |
2214 | 2221 | def http_error_401(self, url, fp, errcode, errmsg, headers, data=None,
|
2215 | 2222 | retry=False):
|
2216 | 2223 | """Error 401 -- authentication required.
|
|
0 commit comments