推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Zuckonit
V2EX  ›  Python

requests 如何带证书上传文件

  •  
  •   Zuckonit · Jul 8, 2014 · 7184 views
    This topic created in 4353 days ago, the information mentioned may be changed or developed.
    下面的语句如何在python 的 requests库里面实现
    filename=/tmp/testfile
    curl --cacert test.cert -X POST -F "hash=$hash_v" -F "filename=@$filename" "https://0.0.0.0:12345/upload/"

    意思是通过POST方法, body有两个参数, 一个是hash, 一个文件
    Supplement 1  ·  Jul 8, 2014
    google一番, 基本都不对, 拼凑测试几次后通过, 总结如下, 希望对遇到同样问题的人有帮助

    filename = '/tmp/test.cert'
    hash_v = 'assumethisisahash'
    with open(filename, 'rb') as f:
    ....requests.post(link, data={'hash': hash_v}, files={'filename':f}, verify='/tmp/test.cert')
    4 replies    2014-07-08 19:17:31 +08:00
    yueyoum
        2
    yueyoum  
       Jul 8, 2014
    request.post(url, cert="test.cert")
    Zuckonit
        3
    Zuckonit  
    OP
       Jul 8, 2014
    @yueyoum 试了报错, @keakon给的link里面也没看到我这种场景的demo, curl可以。能把curl命令翻译成requests不(对了证书我自己生成的)
    Zuckonit
        4
    Zuckonit  
    OP
       Jul 8, 2014
    google一番, 基本都不对, 拼凑测试几次后通过, 总结如下, 希望对遇到同样问题的人有帮助

    filename = '/tmp/test.cert'
    hash_v = 'assumethisisahash'
    with open(filename, 'rb') as f:
    ....requests.post(link, data={'hash': hash_v}, files={'filename':f}, verify='/tmp/test.cert')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   943 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:43 · PVG 04:43 · LAX 13:43 · JFK 16:43
    ♥ Do have faith in what you're doing.