从 Android 到 Python 的 HTTP Post (Apache Mod_Python)
我想将 HTTP Post 数据从 Android 应用程序发送到 Python 脚本(Apache with Mod_Python)。我之前测试过我的 Android 客户端并成功将数据发送到 php 脚本。当我使用表单并将数据发送到我的 Python 脚本时,它表现良好(正在上传或下面的脚本提示“未上传文件”)。
只有当我想将数据从 Android 应用程序发送到 Python 时,我才会遇到问题。
我收到一条错误消息
ValueError:需要超过 1 个值才能解压
这是我的 Python 代码:
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
我的 http 帖子的 Android 代码很长,但在其他设置中工作得很好,所以我现在不发布它(我可以根据要求发布它)。有谁有提示,我需要从哪里开始搜索错误?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了错误:
在我的 HTTP Post 中,我使用“\n”作为换行符。 PHP 对此没有问题,即使它格式错误。 Mod_Python 需要“\r\n”。
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".