Python 2.7版下载错误由urllib.urlretrieve Dropbox的文件 [英] Python 2.7 error downloading Dropbox file by urllib.urlretrieve

查看:487
本文介绍了Python 2.7版下载错误由urllib.urlretrieve Dropbox的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code我用(不介意的形象,这是一个测试一个):

The code I used (don't mind the image, it's a test one):

import urllib
urllib.urlretrieve('https%3A//dl.dropboxusercontent.com/u/95587456/Evenimente/1.jpg','/storage/emulated/0/Temp/1.jpg')

我试图通过其公共Dropbox的链接,下载一个图像,只为这个错误弹出:

I tried to download an image by its public dropbox link, only for this error to pop up:

I/python  ( 3750):  Traceback (most recent call last):
I/python  ( 3750):    File "/home/cristi/Desktop/AplicatieMinister/.buildozer/android/app/main.py", line 102, in <module>
"/home/cristi/Desktop/AplicatieMinister/.buildozer/android/app/main.py", line 63, in IncarcaAfise
I/python  ( 3750):    File "/home/cristi/Desktop/AplicatieMinister/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/urllib.py", line 91, in urlretrieve
I/python  ( 3750):    File "/home/cristi/Desktop/AplicatieMinister/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/urllib.py", line 237, in retrieve
I/python  ( 3750):    File "/home/cristi/Desktop/AplicatieMinister/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/urllib.py", line 205, in open
I/python  ( 3750):    File "/home/cristi/Desktop/AplicatieMinister/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/urllib.py", line 461, in open_file
I/python  ( 3750):    File "/home/cristi/Desktop/AplicatieMinister/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/urllib.py", line 475, in open_local_file
I/python  ( 3750):  IOError: [Errno 2] No such file or directory: 'https://dl.dropboxusercontent.com/u/95587456/Evenimente/1.jpg'

在Windows上运行该code没有问题(它下载),但在Android(编译它作为一个APK由buildozer后),它给人的previous错误。

Running this code on Windows has no issues (it downloads the ), but on android (after compiling it as an APK by buildozer) it gives the previous error.

我尝试添加?(DL)= 1和β(DL)= 0在链路的末端,它在相同的错误结束。另外,我试过urllib.quote链接(和更换'$ 3A'与':')。并且它还是给了这个错误。

I tried adding ?dl=1 and ?dl=0 at the end of the link, and it ended up in the same error. Also, I tried urllib.quote on the link (and replacing the '$3A' with ':') and it still gave this error.

有什么我都忽略了关于如何在Android的urllib而urlretrieve工作?

Is there anything I have overlooked regarding how urllib and urlretrieve work under android?

另外,如果有帮助,Kivy / buildozer是在这个开发中使用。

Also, if it helps, Kivy/buildozer were used in the development of this.

推荐答案

根据堆栈跟踪,似乎 urllib.urlretrieve 认为你的Dropbox URL是本地文件路径,而不是一个因特网网址,并试图将其打开本身。 (也就是说,它会尝试使用 open_local_file )。这应该是基于URL的格式自动确定,但这显然是你的企图逃脱糊涂 :,这应该是不必要的

Based on the stack trace, it appears that urllib.urlretrieve thinks your Dropbox URL is a local file path, as opposed to an Internet URL, and is attempting to open it as such. (I.e., it tries to use open_local_file.) That is supposed to be automatically determined based on the format of the URL, but this is apparently confused by your attempt to escape the ":", which should be unnecessary.

您样品code其实失败对我来说也是这样,只是在Python间preTER:

Your sample code actually fails the same way for me, just in the Python interpreter:

In [1]: import urllib

In [2]: urllib.urlretrieve('https%3A//dl.dropboxusercontent.com/u/95587456/Evenimente/1.jpg','./1.jpg')
...
IOError: [Errno 2] No such file or directory: 'https://dl.dropboxusercontent.com/u/95587456/Evenimente/1.jpg'

既然如此,你确定你跑你认为你所说的是你在不同的平台?在code

That being the case, are you sure you've run the code you thought were you on the different platforms as you mentioned?

刚刚杀青的URL恢复正常工作对我来说:

Just fixing the URL back to normal works for me:

In [1]: import urllib

In [2]: urllib.urlretrieve('https://dl.dropboxusercontent.com/u/95587456/Evenimente/1.jpg','./1.jpg')
Out[2]: ('./1.jpg', <httplib.HTTPMessage instance at 0x10da6d878>)

(我还修改了第二个参数,使之在我的电脑上工作,但这是不相关的。)

(I also modified the second parameter to make it work on my computer, but that's unrelated.)

这篇关于Python 2.7版下载错误由urllib.urlretrieve Dropbox的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆