无法从urllib.request.urlopen获得带有dot结尾的响应
我的脚本看起来像这样,用户名以“”结尾。点。
import urllib.request
url = "https://likee.video/@evadecarle."
response = urllib.request.urlopen(url)
print(response)
结尾点“”。在URL中似乎会引起问题。 如果我将URL更改为url =“ https://likee.video/@11happyness07.12”
它可以正常工作。 我如何使其与结尾点“”。 ?
I have a script looking like this, with a username ending with a "." dot.
import urllib.request
url = "https://likee.video/@evadecarle."
response = urllib.request.urlopen(url)
print(response)
The ending dot "." in the url seems to cause a problem.
If I change the url to url = "https://likee.video/@11Happyness07.12"
it works fine.
How do I make it work with the ending dot "." ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我们尝试获取
https://likee.video/@evadecarle。
使用urllib.requests
,我们会看到:由于远程网站返回302状态代码,这是失败的
(HTTP重定向)。通常,您会使用一个
httpredirecthandler
,类似:不幸的是,url
https://likee.video/@evadecarle。
是一个奇怪的一:它返回
302
状态代码,但不包括位置:
标识重定向目标的标题。
因此,它看起来像
urllib
无法正确处理它。其他人可能会对我纠正我,但看起来
请求
库处理此问题没有问题:
因此,使用
请求
模块可能是最简单的解决方案。If we try to fetch
https://likee.video/@evadecarle.
usingurllib.requests
, we see:It's failing because the remote website is returning a 302 status code
(an http redirect). Normally, you would handle this by using an
HTTPRedirectHandler
, something like:Unfortunately, the URL
https://likee.video/@evadecarle.
is an oddone: it returns a
302
status code, but doesn't include aLocation:
header identifying the redirect target.
Because of this, it looks like
urllib
doesn't handle it properly.Someone else may correct me on this, but it looks like the
requests
library handles this without a problem:
So using the
requests
module may be the simplest solution.