OldGregory
November 30th, 2008, 05:04 AM
I have a DD-WRT-eed Linksys wireless router and I would like to send an http POST to change settings on it, but something is going amiss.
After fiddling with urllib2, I was able to successfully request a page using basic authentication, but trying to post any data resulted in a "httplib.BadStatusLine" error.
After some more googling, I came across this page: http://www.russellbeattie.com/blog/is-this-a-canonical-python-http-post-with-basic-authentication
The author has almost the same problem I have, and he ended up using httplib2 after seeing a comment left on the blog, and it's no wonder: only three simple, no frills-attached lines of code are needed.
Anyway, here is what I am trying to do. The get works. The post results in a httplib.BadStatusLine error, which means the router sent back a status line (like 200, 301, 401, 404, etc) that doesn't make any sense .
import urllib
import httplib2
http = httplib2.Http()
http.add_credentials( 'root', 'xxx' )
#result = http.request( 'http://192.168.1.1/Wireless_Basic.asp', 'GET' )
#result = http.request( 'http://192.168.1.1/Wireless_Basic.asp', 'POST', urllib.urlencode({ 'wl0_ssid':'lol' }) )
print result
exit()
So I'm pretty sure something is wrong with the data I'm trying to send, either it's not enough, or just wrong. If you need to see the webpage source, just say so.
After fiddling with urllib2, I was able to successfully request a page using basic authentication, but trying to post any data resulted in a "httplib.BadStatusLine" error.
After some more googling, I came across this page: http://www.russellbeattie.com/blog/is-this-a-canonical-python-http-post-with-basic-authentication
The author has almost the same problem I have, and he ended up using httplib2 after seeing a comment left on the blog, and it's no wonder: only three simple, no frills-attached lines of code are needed.
Anyway, here is what I am trying to do. The get works. The post results in a httplib.BadStatusLine error, which means the router sent back a status line (like 200, 301, 401, 404, etc) that doesn't make any sense .
import urllib
import httplib2
http = httplib2.Http()
http.add_credentials( 'root', 'xxx' )
#result = http.request( 'http://192.168.1.1/Wireless_Basic.asp', 'GET' )
#result = http.request( 'http://192.168.1.1/Wireless_Basic.asp', 'POST', urllib.urlencode({ 'wl0_ssid':'lol' }) )
print result
exit()
So I'm pretty sure something is wrong with the data I'm trying to send, either it's not enough, or just wrong. If you need to see the webpage source, just say so.