为什么使用请求模块返回服务器代码时会遇到错误?
(我在撰写本文时使用了翻译人员。请理解,有些单词可能不正确。) 我使用请求模块对其进行了测试。如果找不到该站点,则应返回404代码,但有错误。我不知道原因是什么。任何帮助将不胜感激。如何正确返回404代码?
---下面是代码。
import requests as re
a = re.get(input())
print(a.status_code)
错误 : Trackback(最近的最新电话): 文件“”,第1行,在 文件“ C:\ USER \ 82104_DVFQR9F \ AppData \ local \ program \ python \ python \ python310 \ lib \ lib \ site-packages \ requests \ api.py.py”,第75行, 返回请求('get',url,params = params,** kwargs) 文件“ C:\ USER \ 82104_DVFQR9F \ AppData \ local \ program \ python \ python \ python310 \ lib \ lib \ site-packages \ requests \ requests \ api.py”,第61行, 返回session.request(方法=方法,url = url,** kwargs) 文件“ C:\ USER \ 82104_DVFQR9F \ AppData \ local \ program \ python \ python \ python310 \ lib \ lib \ site-packages \ site-packages \ requests \ sessions.py”,第515行 prep = self.prepare_request(req) 文件“ c:\ user \ 82104_dvfqr9f \ appdata \ local \ program \ python \ python \ python310 \ lib \ lib \ site-packages \ requests \ sessions \ sessions.py”,第443行, P.Prepare( 文件“ c:\ user \ 82104_dvfqr9f \ appdata \ local \ program \ python \ python \ python310 \ lib \ lib \ site-packages \ request \ requests \ models.py.py”,第318行, self.prepare_url(url,params) 文件“ c:\ user \ 82104_dvfqr9f \ appdata \ local \ program \ python \ python \ python310 \ lib \ lib \ site-packages \ request \ request.py.py.py”,第392行, 提高错过(错误) requests.exceptions.missingschema:无效的URL'eeee.com':没有提供计划。也许您的意思是 http://eee.com ?
(I used a translator when writing this article. Please understand that some words may be incorrect.)
I tested it using the requests module. If the site cannot be found, a 404 code should be returned, but with an error. I don't know what the reason is. Any help would be appreciated. How to properly return a 404 code?
---Below is the code.
import requests as re
a = re.get(input())
print(a.status_code)
error :
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 515, in request
prep = self.prepare_request(req)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 443, in prepare_request
p.prepare(
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 318, in prepare
self.prepare_url(url, params)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 392, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'eeee.com': No scheme supplied. Perhaps you meant http://eeee.com?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此链接用于如何使用请求模块。
You can use this link for how to work with requests module.