玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容

Python下载七牛图片解析正常却无法下载,请牛帮看下源码

# -*- coding: utf-8 -*-
# flake8: noqa
import os
import string
import random
import tempfile
import requests

from qiniu.compat import is_py2, b
from qiniu.services.storage.uploader import _form_put
from qiniu import Auth
from qiniu import BucketManager

access_key = 'ooooo'
secret_key = 'xxx'
bucket_name = 'faveface'
url_base = '7xj2tu.com1.z0.glb.clouddn.com'

print access_key
print secret_key

q = Auth(access_key, secret_key)

def list_all(bucket_name, bucket=None, prefix=None, limit=None):
    print('List file...')
    if bucket is None:
        bucket = BucketManager(q)
    marker = None
    print(bucket);
    eof = False
    while eof is False:
        ret, eof, info = bucket.list(bucket_name, prefix=prefix, marker=marker, limit=limit)
        marker = ret.get('marker', None)
        for item in ret['items']:
#            print(item['key']+'.jpg')
#            base_url='http://%s//%s'%(url_base,item['key']+'.jpg')
            base_url='http://%s//%s'%(bucket_name+'.qiniudn.com',item['key']+'.jpg')
            print('Processing: '+base_url);
            private_url = q.private_download_url(base_url,expires=3600)
            print(private_url)
            #r = requests.get(private_url)
            #assert r.status_code == 200


list_all(bucket_name)


代码如上,access_key ,secret_key 暂时匿名了,打算下载faveface中的图片,能够list出图片,但是下载出现问题,大神么帮帮忙哈。

将base_url修改成

base_url='http://%s/%s'%(url_base,item['key']+'.jpg')

key签名多了一个/

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/wenda/wd18555.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年06月05日 - 19时09分43秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules