开发者

Why Does My Put request fail?

开发者 https://www.devze.com 2023-02-22 17:32 出处:网络
Using Python 2.5开发者_如何学编程 and httplib...... I am admittedly a python novice.....but this seems straight forward, why doesn\'t this work?

Using Python 2.5开发者_如何学编程 and httplib......

I am admittedly a python novice.....but this seems straight forward, why doesn't this work?

httpConn = HTTPConnection('127.0.0.1', 44789)
httpConn.request('PUT','/ShazaamMon/setmfgdata.cgi?serial=', hwSerialNum)
httpResp = httpConn.getresponse()

xmlResp = httpResp.read()

httpConn.close()

it returns the following response: <HTML><HEAD><TITLE>HTTP 404.......

Any clues anyone???


I think you should replace PUT with GET.

You should consider sanitizing the input, trye

httpConn.request('GET','/ShazaamMon/setmfgdata.cgi?serial=%s' % (urllib.quote(hwSerialNum)))


HTTP 404 means that the resource you requested does not exist. Are you sure that the URL is correct?

Moreover, you put in the body of the request (third parameter of request()) a variable that I think is a parameter of the request.

Try the following:

httpConn.request('PUT','/ShazaamMon/setmfgdata.cgi?serial=' + str(hwSerialNum))

or maybe (if GET is required instead of PUT):

httpConn.request('GET','/ShazaamMon/setmfgdata.cgi?serial=' + str(hwSerialNum))


@Angelom's answer is concise and correct. For a nice example-filled explanation of using PUT in urllib and urllib2 try http://www.voidspace.org.uk/python/articles/urllib2.shtml#data.

0

精彩评论

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