我在网上关注了一个教程并遇到了一些代码:
import random
import urllib.request
def download_web_image(url):
name = random.randrange(1, 1000)
full_name = str(name) + ".jpg"
urllib.request.urlretrieve(url, full_name)
download_web_image("https://buckysroom.org/photos/users/2/resized/2463a86fdf42a1681c66ba8fd6789f9d.jpg")
我正在使用PyCharm作为我的IDE,而且我遇到了追溯错误。
答案 0 :(得分:0)
通常这个错误会提示python3.x,因为没有urllib模块了。实际上它分为几个模块。
对于python 3.x
https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_LisaVoice&text=How%20can%20I%20help%20you%20today.&watson-token=r4H7NZRIVbmROHTbd6Bw6NskKwtLAmowO1Roz%2F2e0HzvdkV7iFxJGKnI8Yk%2BWRL13lBppUzSyef1gRjL2gMuQeAu%2BkEgC9JX9G9hG6sedhvC6FHVIlsWsykkjcWsP%2FxBUzXujYdOJHNoTXoDK2MOZAsD%2F155m44REIZYsyWWk7Pnl9fJNjfZQlu4lIMt38VIJKNq9UXBlTB%2FibSW57H7yRGuoEw0RUrAd6oDSt0qYEewEm0Qr6azD98HeL0NjKRcgiiEpJIwJNyXr6mwYFT7bMpq2qswZD56GtgrXkDoF2NZqi2snSk4XzFubSQsO0oE95bs3jm4VPLukQKnyDD9T63P%2B3%2FVhFokRP%2BA8%2BZ%2FITQu%2FYLo3p6juVTUsXGPL5dEU7JmHpuFSqfQQ%2FHiKJTkJiVRZJ%2B0bjoj9yzy3iDQ%2BEGhKzLxng%2BxOX7qkpoo8DVRUrGrnuCoHaQ04OmS10Ic8AVMVvgYmoJOJ8gntCBDwO5ucjn9xVpkONmzHB%2FJs6NJ%2FJc%2BYkOJsKvo2SNW39U2lE8Mrj2Q%2F0XjPzVKQ%2B40oP2oRPDA0RpvXe09Ka1JHFczt5sxQ8W8YJcKUyXJkmlZ%2FGWnmSDG17Yr4LuolUjnn38lNzhn026VwrQ7LqVYVKoc8hmfwxTDr%2BAuL%2Bv4TYGYW75JJNVzdPN5mgbI32a%2F15YHSnykpCECTQ1PzOT3TaaCu41qV6wsqHCCd%2FaGF3jsvUo%2BWQWDZq%2FM0fkbnsyYaHyOO4AAkm9nADnRiD%2FLLuoHERtuay2YhsyJKagNU4YXJ0ISakxfFvs9K1OnLIRInYliWW84DVDVLLnJHhOBFMUH4vytECdAh2%2BNlwDE2GnzgHDg9QSieItFLnYC6tp2BLSL02502%2Fjv1sw4TEfWETCcTwsK8zPc8g%2F3KX7Pwf24ZgUcjzfXtZiwjVc70vPQsxjxTzLqTzP7Mo61QLmSOkFL&accept=audio%2Fogg
对于python 2.x
import urllib.request
urllib.request.urlretrive("https://your url/name.jpg")
但是在两个版本中,urlretrive的工作原理相同,不需要更改该部分中的任何内容。
答案 1 :(得分:0)
只需删除" .request"从导入行改变它 urllib.request.urlretrieve(url,full_name) 至 urllib.urlretrieve(url,full_name)