开发者

HTTP Post from Android to Python (Apache Mod_Python)

开发者 https://www.devze.com 2023-02-14 17:07 出处:网络
I want to send HTTP Post data from an Android application to a Python script (Apache with Mod_Python). I tested my Android client and send data successfully to a php script before. When I use a form a

I want to send HTTP Post data from an Android application to a Python script (Apache with Mod_Python). I tested my Android client and send data successfully to a php script before. When I use a form and send data to my Python script it performs well (uploading or with the script below prompting 'No file uploaded开发者_JS百科').

I only have problems when I want to send data from my Android app to Python.

I receive an error message

ValueError: need more than 1 value to unpack

Here's my Python code:

def upload(req):

    sys.stderr = open('/var/www/cv/py/errorlog.txt', 'a')

    try: # Windows needs stdio set for binary mode.
        import msvcrt
        msvcrt.setmode (0, os.O_BINARY) # stdin  = 0
        msvcrt.setmode (1, os.O_BINARY) # stdout = 1
    except ImportError:
        pass

if False:
        # do some stuff, not used
else:
    message = 'No file was uploaded'

sys.stderr.close()
sys.stderr = sys.__stderr__

return message

My Android code for the http post is quite long but worked fine in another setting, so I don't post it for now (I can do it on request). Does anyone have a hint, where I need to start searching for the error?


I found the error: In my HTTP Post I used "\n" as a new line character. PHP was fine with that, even if it is malformed. Mod_Python requires "\r\n".

0

精彩评论

暂无评论...
验证码 换一张
取 消