Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python requests login post get response code 500

code below:
#!/bin/env python
# -*- coding: utf-8 -*-

import sys
import requests

#headers = {'User-Agent': 'Mozilla/5.0',"ContentType":"text/xml;charset=utf-8"}
payload = {
    'userName':'myusername',
    'password':'mypasswd',
    'callback':'jQuery17209257929018213263_1425826216682',
    'redirectURL':'http://www.10010.com',
    'redirectType':'01',
    'productType':'01',
    'pwdType':'01',strong text
    'rememberMe':'01'
}
link    = 'https://uac.10010.com/portal/Service/MallLogin'
s = requests.Session()
resp    = s.post(link,data=payload)
print resp
print resp.content
print resp.text

when i run the code ,i get the response 500,but when i copy this link with params in the browser,it works and i could login. i cannot find the reason .i need the help,thanks!

like image 626
psnail Avatar asked Feb 26 '26 01:02

psnail


1 Answers

Try this.

header_content = {'Content-type': 'application/json'} 
js_data = json.dumps({'username': 'myusername', 
             'password': 'mypasswd',
             'callback':'jQuery17209257929018213263_1425826216682',
             'redirectURL':'http://www.10010.com',
             'redirectType':'01',
             'productType':'01',
             'pwdType':'01',
             'rememberMe':'01'})
response = requests.post(link, data=js_data, headers=header_content, verify=False)

if response.status_code == 200:
   print(response.content)

You need to specify content in the header, in your case it is json. Also, as you perform a request through https, certificate verification could cause a problem, so turn the verification off by "verify=False". Also error in json format could be a reason of 500, so to be sure that you are passing appropriate json object, I recommend to use json.dumps(). Hope it helps. Regards!

like image 64
Artur Khromov Avatar answered Feb 28 '26 15:02

Artur Khromov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!