python 404_当url存在时,Python requests.get显示404
甚至没有等待你的测试,我很自信我知道你的bug是什么.I put this url manually in function call it works fine but if I read that file and directly call function with that url, give me error. I have put 3-4 checks while reading f
甚至没有等待你的测试,我很自信我知道你的bug是什么.
I put this url manually in function call it works fine but if I read that file and directly call function with that url, give me error. I have put 3-4 checks while reading file, url is perfectly coming form the file even I tried to print that url inside the called function and I’m receiving that url in function too. still have no clue what is happening ?
很可能你正在使用类似于line in file:或file.readline或其他一些保留换行符的函数来读取URL.所以,你实际上最终得到的不是这个:
url = 'http://www.leboncoin.fr/montres_bijoux/671762293.htm'
… 但是这个:
url = 'http://www.leboncoin.fr/montres_bijoux/671762293.htm\n'
后者将被请求转义为对于不存在的资源而言非常好的URL,因此404错误.
检查这个的最好方法是打印repr(url)而不是print(url).这也将发现其他可能的问题,如嵌入式非打印字符.它不会找到所有内容,例如看起来像的Unicode字符.但实际上并非如此,但这是一个很好的第一次测试. (如果没有找到它,则进行第二次测试,将输出,引号和所有内容复制并粘贴到测试脚本中.)
如果这是问题,修复很简单:
url = url.rstrip()
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)