当前位置:   article > 正文

Python - requests 上传文件及报错_importerror: cannot import name 'appengine' from '

importerror: cannot import name 'appengine' from 'urllib3.contrib

上传文件

import requests 
from requests_toolbelt import MultipartEncoder
import shutil 

# pip install  requests-toolbelt  

def tran(file_path, save_path):
    url = 'http://xxxxx'

    m = MultipartEncoder(fields={'file': ('a.pdf', open(file_path, 'rb'), 'application/pdf')} ) 
    print('-- m : ', m) 

    res = requests.post(url, data=m, headers={'Content-Type': m.content_type}, timeout=60*15)
    l = len(res.text.strip())
    # print('-- ret : ', res, file_path, '\n---------\n', res.text)  
    print('-- ret : ', res, l)  

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

报错 1

ImportError: cannot import name ‘appengine’ from ‘urllib3.contrib’


升级 requests-toolbelt

pip install --upgrade twine requests-toolbelt
  • 1

根据 stackoverflow
https://stackoverflow.com/questions/76175487/sudden-importerror-cannot-import-name-appengine-from-requests-packages-urlli


报错 2

ConnectionResetError(54, ‘Connection reset by peer’)

如果你的接口只能内网访问,可以检查下你的网络环境(是否用了 本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/695660

推荐阅读
相关标签