jack-X
jack-X

Reputation: 287

post parameters in python

I've tried a lot of codes to post parameters through urllib or httplib.

my parameter

So, this is my code:

import httplib,urllib
para = urllib.urlencode({"username":"[email protected]","password":"test"})
conn = httplib.HTTPconnection("account.example.com") #consider it's https !
conn.request("POST","/eng/auth/login",para)
res = conn.getresponse()
print res.status , res.reason

It's said 301 moved permanently! Any tips or lead … ? Thank you even for reading <3

Upvotes: 0

Views: 486

Answers (1)

koblas
koblas

Reputation: 27088

You need to encode the parameters:

params = urllib.urlencode({"username":"[email protected]","password":"test"})

The 301 might be totally legitimate, your example is posting to a login handler which will typically accept the POST, issue a Cookie and redirect you to the "correct" page to handle your session.

First take a look at the response headers, see if there is a Cookie and what the page is that you are being redirected to. This should help you figure it out.

Upvotes: 1

Related Questions