[英]urllib.urlretrieve() is not working after importing the library
I imported urllib module and tried to use urllib.urlretrieve() function with some arguments.我导入了 urllib 模块并尝试将 urllib.urlretrieve() function 与一些 arguments 一起使用。 Then it got the error "attributeError: module 'urllib' has no attribute 'urlretrieve'"
然后它得到错误“attributeError:模块'urllib'没有属性'urlretrieve'”
I tried with both python 2x and 3x.我尝试了 python 2x 和 3x。
import urllib
import json
import requests
count=1
req=requests.get("http://meme-api.herokuapp.com/gimme")
json_data = json.loads(req.text)
imgs="memes-"+str(count)+".jpg"
print(imgs)
urllib.urlretrieve(json_data["url"],imgs)
print(imgs + "is saved")
"attributeError: module 'urllib' has no attribute 'urlretrieve'" “attributeError:模块 'urllib' 没有属性 'urlretrieve'”
use urlib.request.urlretrieve() instead of urllib.retrieve()使用 urllib.request.urlretrieve() 而不是 urllib.retrieve()
import urllib.request
import json
import requests
count=1
req=requests.get("http://meme-api.herokuapp.com/gimme")
json_data = json.loads(req.text)
imgs="memes-"+str(count)+".jpg"
print(imgs)
urllib.request.urlretrieve(json_data["url"],imgs)
print(imgs + "is saved")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.