Python报错“urllib2.HTTPError: HTTP Error 405: Not Allowed”的解决方法

本文介绍了解决使用Python的urllib2模块发送GET或HEAD请求时遇到的HTTP 405 Method Not Allowed错误的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py PS C:\Users\29735\Desktop\D创作> & D:/python课程/python2/python.exe c:/Users/29735/Desktop/D创作/day01.py Traceback (most recent call last): File "D:\python课程\python2\Lib\site-packages\urllib3\response.py", line 748, in _error_catcher yield File "D:\python课程\python2\Lib\site-packages\urllib3\response.py", line 1209, in read_chunked chunk = self._handle_chunk(amt) ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python课程\python2\Lib\site-packages\urllib3\response.py", line 1146, in _handle_chunk value = self._fp._safe_read(amt) # type: ignore[union-attr] ^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python课程\python2\Lib\http\client.py", line 633, in _safe_read raise IncompleteRead(data, amt-len(data)) http.client.IncompleteRead: IncompleteRead(1447 bytes read, 8793 more expected) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\python课程\python2\Lib\site-packages\requests\models.py", line 820, in generate yield from self.raw.stream(chunk_size, decode_content=True) File "D:\python课程\python2\Lib\site-packages\urllib3\response.py", line 1057, in stream yield from self.read_chunked(amt, decode_content=decode_content) File "D:\python课程\python2\Lib\site-packages\urllib3\response.py", line 1189, in read_chunked with self._error_catcher(): File "D:\python课程\python2\Lib\contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "D:\python课程\python2\Lib\site-packages\urllib3\response.py", line 775, in _error_catcher raise ProtocolError(f"Connection broken: {e!r}", e) from e urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(1447 bytes read, 8793 more expected)', IncompleteRead(1447 bytes read, 8793 more expected)) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\Users\29735\Desktop\D创作\day01.py", line 19, in <module> res=requests.get(url=url_detail,headers=headers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python课程\python2\Lib\site-packages\requests\api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python课程\python2\Lib\site-packages\requests\api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python课程\python2\Lib\site-packages\requests\sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python课程\python2\Lib\site-packages\requests\sessions.py", line 746, in send r.content File "D:\python课程\python2\Lib\site-packages\requests\models.py", line 902, in content self._content = b"".join(self.iter_content(CONTENT_CHUNK_SIZE)) or b"" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python课程\python2\Lib\site-packages\requests\models.py", line 822, in generate raise ChunkedEncodingError(e) requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(1447 bytes read, 8793 more expected)', IncompleteRead(1447 bytes read, 8793 more expected)) PS C:\Users\29735\Desktop\D创作>
最新发布
06-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值