无法在python中使用urrlib打开站点

2024-10-16 11:24:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个restapi服务器运行在localhost:8080

基本上,我在这个站点上运行一个示例:https://github.com/spray/spray-template/tree/on_spray-can_1.1/src/main/scala/com/example

在我的本地主机:8080 I见

"Say hello to spray-routing on spray-can!"

消息。。在

现在我的python代码是:

import urllib
proxies = {'http': 'http://proxy.abcd.com:800'}
response = urllib.urlopen("http://localhost:8080",proxies=proxies)
print response.read()

我看到的是:

^{pr2}$

所以,我在代理后面工作。我已经指定了代理,但它仍然不工作。 有什么线索吗

谢谢


Tags: https服务器comrestapilocalhosthttp示例代理
1条回答
网友
1楼 · 发布于 2024-10-16 11:24:34

localhost:8080只能从您的电脑访问,不能从其他地方访问。因此,当您使用这样的代理时,proxy.abcd.com:800,来自该代理服务器,您的{}是无法访问的。这就是为什么它不适合你。如果你真的需要测试代码,把url改成任何其他公开可见的网站,比如google,yahoo,example等等

response = urllib.urlopen("http://www.example.com",proxies=proxies)

或者,删除代理:

^{pr2}$

相关问题 更多 >