python urllib.request.urlopen 递归失败
所以我有代码,
def constructGraph(self,url,doit=5):
if doit!=0:
m = urllib.request.urlopen(url)
print('test')
self.constructGraph('http://example.com',doit-1)
但当我运行它时,它只运行第一个 m = urllib.request.urlopen(url)
并且只打印一次测试,即使它应该执行两次......
当我运行调试器时,它甚至不会进入第二次递归的 print('test') 行,而只会退出
我做错了什么?
我正在使用 python 3
so i have the code
def constructGraph(self,url,doit=5):
if doit!=0:
m = urllib.request.urlopen(url)
print('test')
self.constructGraph('http://example.com',doit-1)
but then when I run it, it only runs the first m = urllib.request.urlopen(url)
and only prints test once even though it supposed to do it twice...
and when i run the debugger, it wouldn’t even go to the print('test') line on the second recursion and would just exit
what did i do wrong?
i'm using python 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您一次只能打开一个请求。尝试在 urlopen 调用之前放置一条 print 语句。
Perhaps you can only have one request open at a time. Try putting a print statement before the urlopen call.