V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
Concise
V2EX  ›  Python

requests 发送 formdata 表单如何提交 FileStorage 数据

  •  
  •   Concise · 2019-12-26 02:06:08 +08:00 · 3016 次点击
    这是一个创建于 1582 天前的主题,其中的信息可能已经有所发展或是发生改变。
    前端用表单给我发来一个文件 然后我需要再将这个文件用表单提交给另外一个地址
    我拿到这个文件数据后发现是 FileStorage 类型 当我准备直接拿去提交的时候突然想到以往表单提交都是用 open 打开本地文件的方式 这下我就懵逼了 难道我只能先写出到本地然后在 open 后提交 这样是不是太蠢了... 有没有直接转换的方法呀
    todd7zhang
        1
    todd7zhang  
       2019-12-26 10:14:50 +08:00
    只要你的 FileStorage 有 read 的实现,那就直接传就行了
    requests.post(url, files={'f_name': open('tmp.file', 'r')})
    requests.post(url, files={'f_name': file_storage_instance})
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3602 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:44 · PVG 18:44 · LAX 03:44 · JFK 06:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.