【问题标题】:Python multipart not workingPython多部分不起作用
【发布时间】:2016-12-17 02:39:14
【问题描述】:

发布数据

POSTDATA =-----------------------------204994970613471446171879029128
Content-Disposition: form-data; name="f"; filename="shell.php"
Content-Type: application/x-php

<?php
echo("oi");
?>
-----------------------------204994970613471446171879029128
Content-Disposition: form-data; name="v"

up
-----------------------------204994970613471446171879029128--

表格

<form method=post enctype=multipart/form-data><input type=file name=f><input name=v type=submit id=v value=up>

Python

import requests 
try:
    files = {"f": open("page.php", "rb"),"v":"up"}
    r = requests.post("http://soportetecnico.nixiweb.com/up.php", files=files, headers={"Content-type": "application/x-php"})
    print r.text
except Exception as e:
    print e

我需要发送一个 PHP 文件以使用 python 上传吗? 我不知道我做错了什么。 提前感谢您的帮助=]

【问题讨论】:

    标签: php python-2.7 python-3.x request python-requests


    【解决方案1】:

    您应该在请求中将filesdata 分开:

    import requests 
    try:
        files = {"f": open("page.php", "rb")}
        values = {"v":"up"}
        r = requests.post("http://soportetecnico.nixiweb.com/up.php", files=files, data=values, headers={"Content-type": "application/x-php"})
        print r.text
    except Exception as e:
        print e
    

    【讨论】:

    • @LeandroCampos,尝试将 php 文件作为简单文本 {"f": open("page.php")} 打开,而不是字节。结果一样?
    • @LeandroCampos 究竟是什么不起作用?你得到了什么?有什么错误吗?回应是什么?
    • Header {'Content-Length': '508', 'Accept-Encoding': 'gzip, deflate', 'Accept': '/ i>', 'User-Agent': 'python-requests/2.8.1', 'Connection': 'keep-alive', 'Content-type': 'application/x-php'} 响应

      问题没有上传。跨度>
    猜你喜欢
    • 2017-10-27
    • 2016-08-03
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 2021-04-01
    • 1970-01-01
    • 2013-12-09
    相关资源
    最近更新 更多