qiniu / python-sdk

Qiniu Resource (Cloud) Storage SDK for Python
MIT License
544 stars 259 forks source link

升级v7.11.x后上传报错 #439

Closed hoveychen closed 10 months ago

hoveychen commented 1 year ago

回退v7.10.0后问题修复。

调用代码

    qiniu_auth = qiniu.Auth(access_key, secret_key)
    key = f'{date}/{time}-{ran:02d}.{file_ext}'
    token = qiniu_auth.upload_token(qiniu_bucket, key, 3600)
    qiniu.put_data(token, key, bytes)

    return f'{qiniu_domain}/{key}'

错误提示

Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/root/miniconda3/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/root/miniconda3/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/miniconda3/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/root/xxxxxxxxxxxx.py", line 93, in fast_swap_face
    output_url = utils.upload_image(img)
  File "/root/xxxxxxxxxxxx.py", line 127, in upload_image
    return upload_file(byte_encode, 'png')
  File "/root/xxxxxxxxxxxx.py", line 63, in upload_file
    qiniu.put_data(token, key, bytes)
  File "/root/miniconda3/lib/python3.10/site-packages/qiniu/services/storage/uploader.py", line 45, in put_data
    return _form_put(up_token, key, final_data, params, mime_type,
  File "/root/miniconda3/lib/python3.10/site-packages/qiniu/services/storage/uploader.py", line 108, in _form_put
    url = config.get_default('default_zone').get_up_host_by_token(up_token, hostscache_dir)
  File "/root/miniconda3/lib/python3.10/site-packages/qiniu/region.py", line 45, in get_up_host_by_token
    up_hosts = self.get_up_host(ak, bucket, home_dir)
  File "/root/miniconda3/lib/python3.10/site-packages/qiniu/region.py", line 113, in get_up_host
    bucket_hosts = self.get_bucket_hosts(ak, bucket, home_dir)
  File "/root/miniconda3/lib/python3.10/site-packages/qiniu/region.py", line 144, in get_bucket_hosts
    hosts = compat.json.loads(self.bucket_hosts(ak, bucket)).get('hosts', [])
AttributeError: 'NoneType' object has no attribute 'get'
lihsai0 commented 1 year ago

@hoveychen 未能复现。您那边可以稳定复现嘛?

初步判断是查询上传域名出问题了。如果您可以稳定复现,麻烦您 debug 一下 bucket_hosts(ak, bucket) 看看有没有更多关于请求错误信息。

r = qiniu.region.Region()
d = r.bucket_hosts(access_key, qiniu_bucket)
print(d)

最好可以 debug 看下 bucket_hosts 内部的 _resp 的内容。

OlnyBigRoc commented 1 year ago

bucket_hosts

HTTPSConnectionPool(host='api.qiniu.com', port=443): Max retries exceeded with url: /v4/query?ak=&bucket= (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)')))

lihsai0 commented 1 year ago

@OlnyBigRoc 请检查 ak 与 bucket 设置正确。如果检查无误,麻烦附上复现代码~

OlnyBigRoc commented 1 year ago

@OlnyBigRoc 请检查 ak 与 bucket 设置正确。如果检查无误,麻烦附上复现代码~

@lihsai0 对不起哇,我的问题是,挂了代理,没有把qbox.me加入绕过规则导致的,打扰了