开发者

CouchDB POST response, which was sent via curl via Python's subprocess module, is getting lost (curl code 53). Why is that?

I'm trying to add a document to couchDB from python using curl via the subprocess module. I can do it fine from the command line but not from python.

Here is the command line code

curl -X POST http://doug:enter@localhost:5984/mydb/ -H "Content-Type: application/json" -d {}

The document is created each and every time with this command. However, the same command from Python via the subprocess module fails. I'm wondering if anyone can pinpoint where, and why, the reply gets lost (CouchDB should send a response, but the error is that curl isn't receiving one).

here is the code.

import subprocess

args = ['curl', '-X', 'POS开发者_运维知识库T', 'http://doug:enter@localhost:5984/mydb/', '-H', '"Content-Type: application/json"', '-d', '{}']

try:
    retcode = subprocess.call(args)
except OSError:
    print('os error')
except ValueError:
    print('value error')

print(retcode)

Additional Information:

I'm running Kubuntu 11.04, curl 7.21.3, and Python 2.7.1

The CouchDB database is on my local machine and as I mentioned above, its working perfectly.


You aren't including shell=True. Subprocess won't use your shell if you don't, so you'll have differences from running on the command line.

retcode = subprocess.call(args, shell=True)

That should fix your problem. Note that this may cause args to not work quite correctly, as it may want a string instead. If that is the case try:

retcode = subprocess.call(' '.join(args), shell=True)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜