Python 中 Urllib 的意外行为
我的系统不支持任何代理。
params = urllib.urlencode({'search':"August Rush"})
f = urllib.urlopen("http://www.thepiratebay.org/search/query", params)
这会进入无限循环(或者只是挂起)。显然我可以摆脱这个并使用 FancyUrlOpener 并自己创建查询而不是传递参数。但是,我认为按照我现在的方式做是一种更好、更干净的方法。
编辑:这更多的是一个网络问题,其中我的 Ubuntu 工作站配置为不同的代理。必须做一些改变并且它起作用了。谢谢你!
My system is not behind any proxy.
params = urllib.urlencode({'search':"August Rush"})
f = urllib.urlopen("http://www.thepiratebay.org/search/query", params)
This goes onto an infinite loop(Or just hangs). I can obviously get rid of this and use FancyUrlOpener and create the query myself rather than passing it parameters. But, I think doing the way I'm doing now is a better and cleaner approach.
Edit: This was more of a networking problem in which my Ubuntu workstation was configured to a different proxy. Had to do certain changes and it worked. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发布的代码对我来说工作得很好,在 Windows 上使用 Python 2.7.2。
您是否尝试过使用 http 调试工具,例如 Fiddler2 来查看您的程序与网站?
如果您在本地主机的端口 8888 上运行 Fiddler2,您可以执行以下操作来查看请求和响应:
The posted code works fine for me, with Python 2.7.2 on Windows.
Have you tried using a http-debugging tool, like Fiddler2 to see the actual conversation going between your program and the site?
If you run Fiddler2 on port 8888 on localhost, you can do this to see the request and response:
这对我有用:
我使用启用了网络检查器的 Google Chrome 打开 http://www.thepiratebay.org 。我将“August Rush”输入搜索字段,然后按“搜索”。然后我分析了发送的标头并执行了上面的代码。
This works for me:
I opened http://www.thepiratebay.org with Google Chrome with network inspector enabled. I put "August Rush" into the search field and pressed 'Search'. Then i analyzed the headers sent and did the code above.