简体   繁体   English

Python3 urlopen在localhost上获得“504网关超时”(127.0.0.1)

[英]Python3 urlopen get “504 Gateway timeout” on localhost(127.0.0.1)

I got a 504 gateway timeout when use urlopen to open a site on localhost,while my browser can open it normally. 当使用urlopen在localhost上打开一个站点时,我得到了504网关超时,而我的浏览器可以正常打开它。

This site is on localhost and I can use my browser to prove that it works fine. 这个站点在localhost上,我可以使用我的浏览器来证明它工作正常。 I try to enable and disable system proxy settings but it has no effect. 我尝试启用和禁用系统代理设置但它没有任何效果。

from urllib.request import urlopen
urlopen("http://127.0.0.1") 
#raise urllib.error.HTTPError: HTTP Error 504: Gateway Time-out

First, add http:// before 127.0.0.1 . 首先,在127.0.0.1之前添加http:// Second, give us more information on the server you are running, like, are you using proxy for localhost? 其次,给我们提供有关您正在运行的服务器的更多信息,例如,您是否使用localhost代理?

It seems like that urllib.request.urlopen in python3.7 don't understand subnet like 127.0.0.0/8 in no_proxy environment variable. 好像python3.7中的urllib.request.urlopen在no_proxy环境变量中不了解像127.0.0.0/8这样的子网。 Now I use localhost instead of 127.0.0.1 and it works. 现在我使用localhost而不是127.0.0.1并且它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM