0

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').

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?

3
  • Does it tell you which line the error comes from? Because none of that looks like it should be unpacking values. Commented Mar 1, 2011 at 18:04
  • I cannot see the complete trace in the errorfile (/var/log/apache2/error.log). The last lines refer to importer.py, publisher.py and util.py in mod_python. Can I change the settings of Apache(?) to see the complete trace in the error.log? Commented Mar 1, 2011 at 18:07
  • I don't know. If it's in mod_python, that suggests that there's something wrong with the configuration of Apache. I should add that mod_python has apparently been superseded by mod_wsgi - I don't know if that would work better for you. Commented Mar 1, 2011 at 18:15

1 Answer 1

1

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".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.