Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > help on HTTP 400 Bad Request syntax error on urllib2.urlopen

Reply
Thread Tools

help on HTTP 400 Bad Request syntax error on urllib2.urlopen

 
 
icarreon icarreon is offline
Junior Member
Join Date: Jan 2012
Posts: 1
 
      01-10-2012
Hi,
I have a piece of code where I log on to a web site - through a proxy server and using web site credentials. I log in just fine. Then I try to get into a page where I sent the session Id I got, the cookies seem
to be sent just fine but I get a HTTP 400 Bad Request. Please see the syntax of my request and let me know what I'm missing. I'd really appreciate any feedback on this!

Thanks a lot in advance,
Igor

import urllib, urllib2, cookielib
import requests
proxy_info = {
'user' : 'myuser',
'pass' : 'mypassword',
'host' : "myproxy.company.com",
'port' : 8080
}
# build a new opener that uses a proxy requiring authorization
proxy_support = urllib2.ProxyHandler({"http" : "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})
cj = cookielib.CookieJar()
cookie_h = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler(debuglevel=1) , cookie_h)
headers={'User-agent' : 'Mozilla/5.0'}
# install it
urllib2.install_opener(opener)
url = 'http://www.targetsite.com/LogIn.asp?user_id=&user_p assword=myapppassword'
f = urllib2.urlopen(url)
html = f.read()
print html
url2 = 'http://www.targetsite.com/Main.asp?uid=&sid=3294799 60 HTTP/1.1'
response = urllib2.urlopen (url2)
html2 = response.read()
print html2

I get this back:
************************************************** *******************************
send: 'GET http://www.targetsite.com/Main.asp?u...&sid=329479960 HTTP/1.1 HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: www.targetsite.com\r\nProxy-Authorization: Basic aWNhcnJlb246YWdqYTEZ\r\nCookie: ASPSESSIONIDAQBASTST=CGDGDKDBEDEAGJJOINKPFGCC\r\nC onnection: close\r\nUser-Agent: Python-urllib/2.7\r\n\r\n'
reply: 'HTTP/1.1 400 Bad Request\r\n'
header: Cache-Control: no-cache
header: Pragma: no-cache
header: Content-Type: text/html; charset=utf-8
header: Proxy-Connection: close
header: Connection: close
header: Content-Length: 730
Traceback (most recent call last):
File "C:\Aptana\myDev\root\nested\LaunchApp.py", line 45, in <module>
response = urllib2.urlopen (url2)
File "C:\PYTHON27\LIB\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\PYTHON27\LIB\urllib2.py", line 400, in open
response = meth(req, response)
File "C:\PYTHON27\LIB\urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "C:\PYTHON27\LIB\urllib2.py", line 438, in error
return self._call_chain(*args)
File "C:\PYTHON27\LIB\urllib2.py", line 372, in _call_chain
result = func(*args)
File "C:\PYTHON27\LIB\urllib2.py", line 521, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP 400 Bad Request flamesfan ASP .Net 2 08-10-2009 07:07 PM
HTTP 400 bad request matt@mailinator.com Computer Support 43 02-28-2007 01:44 PM
Http/1.1 400 bad request Learner ASP .Net 3 10-26-2006 05:07 PM
FIX: "HTTP 400 - Bad request" error message in the .NET Framework =?Utf-8?B?U2F0aHlhIHNoYW5rYXI=?= ASP .Net 0 03-30-2005 06:25 AM
HTTP/1.1 400 Bad Request =?Utf-8?B?Sm9obiBIYXllcw==?= ASP .Net 1 09-26-2004 05:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57