0
votes

EDIT: I've restated the problem as not only can I not login, but I can't even make a simple POST request without an error. See code below, it should return a json list, instead I'm getting an error page.

import urllib2
import cookielib
import calendar
import datetime
opener = urllib2.build_opener(
    urllib2.HTTPRedirectHandler(),
    urllib2.HTTPHandler(debuglevel = 0),
    urllib2.HTTPSHandler(debuglevel = 0),
    urllib2.HTTPCookieProcessor(cookielib.CookieJar()),
)
opener.addheaders = [
   ('User-agent', "Mozilla/5.0"),
   ("Content-Type", "application/json")
]
data = '{"searchFilter":{"TimeFrame":10000,"NotTradingExotics":false,"Page":0,"PageSize":20,"AffiliateId":-1,"SortExpression":"Ranking","SortDirection":"Ascending"}}'.encode()
tmp = calendar.timegm(datetime.datetime.now().utctimetuple()) * 1000
url = "https://www.zulutrade.com/WebServices/Performance.asmx/SearchProviders?_tsmp=" + str(tmp)
opener.open(url, data)
res = opener.open(url, data)
print opener.handlers[7].cookiejar._cookies
if "An unexpected error occured" in res.read():
    raise Exception("Login failed")
2

2 Answers

1
votes

I checked https://www.zulutrade.com/ login form with HTTPFox (a Firefox plugin to read requests) and you're missing the _tsmp QUERY_STRING parameter that is used in the POST url that handle the login. I think your JSON post is correct, but you miss that parameter (I think they use it to avoid reply-attacks).

HTTPFox showing the parameter

1
votes

This is not a direct answer to your question, but you might wanna consider using the (slightly more simple) code below:

import urllib2,cookielib

def Login(username,password):
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
    url1 = "https://www.zulutrade.com"
    url2 = "https://www.zulutrade.com/WebServices/User.asmx/Login"
    data = "?username="+username+"&password="+password
    socket = opener.open(url1)
    socket = opener.open(url2,data)
    return socket.read()