user1613263 user1613263 - 8 months ago 84
Python Question

why I can't log in this web with python

This is my python codeļ¼ŽI want to log in this website with python, but it can't come true.

import sys, time, os, re
import urllib, urllib2, cookielib

loginurl = ''
#loginurl = ''

cookie = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))

params = {
'username' : 'XXXX',
'password' : 'XXXX',
'lt' : '_c573C07C4-AD13-CD25-85E9-CC917AF0433F_k42B35CAA-C2E7-7B2C-A7A1-9FD4E6CBE30F',
'_eventId' : 'submit'

req = urllib2.Request(loginurl,urllib.urlencode(params))
res = urllib2.urlopen(req).read()
m ='\s+(.+?)\s+',str(cookie))
jsession=re.sub(r'\s+', '',
#print jsession

req1 = urllib2.Request(loginurl,urllib.urlencode(params),header)
res1 = urllib2.urlopen(req1)
print res1.geturl()

Answer Source

Ive had similar problems before because of user-agent issues. Try log in normally (via your browser of choice) and take a look at whatever header info is sent. Try mimic that in your script.

If you don't know how to set the headers check this out: How do I add a header to urllib2 opener?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download