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
thisiskx
V2EX  ›  Python

requests 上传文件求教

  •  
  •   thisiskx · 2019-03-14 12:58:10 +08:00 · 2502 次点击
    这是一个创建于 1863 天前的主题,其中的信息可能已经有所发展或是发生改变。
    需要上传文件的网址: http://221.226.86.226:9012/nyqc//uploader.jsp?ftype=0&type=2&relationId=338&bussiId=20190313162759510770#
    尝试用
    requests.post(url, headers=headers, file={'file':open(filepath, 'rb')})
    requests.post(url, headers=headers, data=MultipartEncoder(fields={'file': (os.path.basename(filepath), open(filepath, 'rb'), "image/jpeg")}))
    均可以返回结果{"status":true,"newName":"null"},但图片就是上传不上。
    试过各种办法都无法处理,求大佬们帮忙。
    14 条回复    2019-03-14 14:04:44 +08:00
    Leigg
        1
    Leigg  
       2019-03-14 13:06:39 +08:00 via iPhone
    接口调用说明?
    thisiskx
        2
    thisiskx  
    OP
       2019-03-14 13:15:50 +08:00
    @Leigg 大佬 我是菜鸟 不知道啥接口调用说明 能否请大佬帮忙看一下
    jaylee4869
        3
    jaylee4869  
       2019-03-14 13:16:49 +08:00
    @thisiskx API 文档。。。
    thisiskx
        4
    thisiskx  
    OP
       2019-03-14 13:17:24 +08:00
    @jaylee4869 没有文档。。。
    WordTian
        5
    WordTian  
       2019-03-14 13:25:16 +08:00
    ![]( https://i.loli.net/2019/03/14/5c89e4923c43b.png)
    接收文件上传的接口 url 就不是你发的那个,建议补充些前端基础知识
    thisiskx
        6
    thisiskx  
    OP
       2019-03-14 13:27:42 +08:00
    @WordTian 接口是我发的这个没错,我 post 图片文件也提示成功,但是就是没有图片,就不知道什么问题了,大佬帮忙看一下
    yushenglin
        7
    yushenglin  
       2019-03-14 13:44:05 +08:00
    这要看下你的接收端也就是 response 的接口说明了,看要什么格式,有什么要求
    thisiskx
        8
    thisiskx  
    OP
       2019-03-14 13:48:02 +08:00
    @yushenglin 要怎么看呢,大佬教一下
    WordTian
        9
    WordTian  
       2019-03-14 13:51:22 +08:00
    @thisiskx 找接口文档啊,要是你们公司是口口相传型的,就找负责这个接口的人问啊
    yushenglin
        10
    yushenglin  
       2019-03-14 13:51:28 +08:00
    你写项目没有开发文档和说明的吗?我晕了,你要是写后端的,就去问下你后端那边的人
    thisiskx
        11
    thisiskx  
    OP
       2019-03-14 13:52:04 +08:00
    @WordTian 这个不是我们公司的网页呀。。。所以不是我们公司的网页是不是一般都搞不定的呀。。
    sowish
        12
    sowish  
       2019-03-14 14:01:16 +08:00
    看看是不是验证了 Content-type 头
    WordTian
        13
    WordTian  
       2019-03-14 14:02:41 +08:00
    @thisiskx 那你就去分析他的前端执行逻辑吧,分析出来之后,用 request 模拟请求。不过就算这么干,很多参数也得靠猜的
    jugelizi
        14
    jugelizi  
       2019-03-14 14:04:44 +08:00   ❤️ 1
    求助 怎么破解别人的 QQ 密码
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3630 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:28 · PVG 18:28 · LAX 03:28 · JFK 06:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.