python27 post requests fails












2















I used this code to log-in to baiscopelk.com




  • In Python 3.6, print(res_1) == <Response [302]>

  • but in Python 2.7 I get print(res_1) == <Response [403]>


I can't understand the problem



import requests

headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Origin': 'https://www.baiscopelk.com',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3) AppleWebKi'
't/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Referer': 'https://www.baiscopelk.com/wp-login.php',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'si,en;q=0.9,en-US;q=0.8',
}

data = {
'log': 'baiscopelk.username',
'pwd': 'baiscopelk.password',
'wp-submit': 'Log In',
'redirect_to': 'https://www.baiscopelk.com/wp-admin/',
'testcookie': '1'
}
res_0 = requests.get('https://www.baiscopelk.com/wp-login.php', headers=headers)
res_1 = requests.post('https://www.baiscopelk.com/wp-login.php', headers=headers, data=data, cookies=res_0.cookies,
allow_redirects=False)

print(res_1)









share|improve this question




















  • 1





    have you tried using json.dumps(data) instead of just data in requests.post?

    – Upasana Mittal
    Nov 13 '18 at 18:20











  • yes. <Response [403]>

    – Gayan Jeewantha
    Nov 13 '18 at 18:47






  • 2





    It is so strange, i make a same request by py2x and py3x but 2x still returns 403 3x returns 302. The difference is the order of param or encode

    – kcorlidy
    Nov 14 '18 at 8:51








  • 1





    Also i have checked the difference on requests's files, but no difference(i copied py3x module's files to py2x folder but it still responds 403)!

    – kcorlidy
    Nov 15 '18 at 13:16






  • 1





    I even build a simple post function by urllib3, and still gets same result. It seems a very difficult question, because it may associate with standard library.

    – kcorlidy
    Nov 15 '18 at 13:27
















2















I used this code to log-in to baiscopelk.com




  • In Python 3.6, print(res_1) == <Response [302]>

  • but in Python 2.7 I get print(res_1) == <Response [403]>


I can't understand the problem



import requests

headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Origin': 'https://www.baiscopelk.com',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3) AppleWebKi'
't/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Referer': 'https://www.baiscopelk.com/wp-login.php',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'si,en;q=0.9,en-US;q=0.8',
}

data = {
'log': 'baiscopelk.username',
'pwd': 'baiscopelk.password',
'wp-submit': 'Log In',
'redirect_to': 'https://www.baiscopelk.com/wp-admin/',
'testcookie': '1'
}
res_0 = requests.get('https://www.baiscopelk.com/wp-login.php', headers=headers)
res_1 = requests.post('https://www.baiscopelk.com/wp-login.php', headers=headers, data=data, cookies=res_0.cookies,
allow_redirects=False)

print(res_1)









share|improve this question




















  • 1





    have you tried using json.dumps(data) instead of just data in requests.post?

    – Upasana Mittal
    Nov 13 '18 at 18:20











  • yes. <Response [403]>

    – Gayan Jeewantha
    Nov 13 '18 at 18:47






  • 2





    It is so strange, i make a same request by py2x and py3x but 2x still returns 403 3x returns 302. The difference is the order of param or encode

    – kcorlidy
    Nov 14 '18 at 8:51








  • 1





    Also i have checked the difference on requests's files, but no difference(i copied py3x module's files to py2x folder but it still responds 403)!

    – kcorlidy
    Nov 15 '18 at 13:16






  • 1





    I even build a simple post function by urllib3, and still gets same result. It seems a very difficult question, because it may associate with standard library.

    – kcorlidy
    Nov 15 '18 at 13:27














2












2








2


2






I used this code to log-in to baiscopelk.com




  • In Python 3.6, print(res_1) == <Response [302]>

  • but in Python 2.7 I get print(res_1) == <Response [403]>


I can't understand the problem



import requests

headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Origin': 'https://www.baiscopelk.com',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3) AppleWebKi'
't/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Referer': 'https://www.baiscopelk.com/wp-login.php',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'si,en;q=0.9,en-US;q=0.8',
}

data = {
'log': 'baiscopelk.username',
'pwd': 'baiscopelk.password',
'wp-submit': 'Log In',
'redirect_to': 'https://www.baiscopelk.com/wp-admin/',
'testcookie': '1'
}
res_0 = requests.get('https://www.baiscopelk.com/wp-login.php', headers=headers)
res_1 = requests.post('https://www.baiscopelk.com/wp-login.php', headers=headers, data=data, cookies=res_0.cookies,
allow_redirects=False)

print(res_1)









share|improve this question
















I used this code to log-in to baiscopelk.com




  • In Python 3.6, print(res_1) == <Response [302]>

  • but in Python 2.7 I get print(res_1) == <Response [403]>


I can't understand the problem



import requests

headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Origin': 'https://www.baiscopelk.com',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3) AppleWebKi'
't/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Referer': 'https://www.baiscopelk.com/wp-login.php',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'si,en;q=0.9,en-US;q=0.8',
}

data = {
'log': 'baiscopelk.username',
'pwd': 'baiscopelk.password',
'wp-submit': 'Log In',
'redirect_to': 'https://www.baiscopelk.com/wp-admin/',
'testcookie': '1'
}
res_0 = requests.get('https://www.baiscopelk.com/wp-login.php', headers=headers)
res_1 = requests.post('https://www.baiscopelk.com/wp-login.php', headers=headers, data=data, cookies=res_0.cookies,
allow_redirects=False)

print(res_1)






python python-requests






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 18:06









user2722968

2,66211637




2,66211637










asked Nov 13 '18 at 17:25









Gayan JeewanthaGayan Jeewantha

236




236








  • 1





    have you tried using json.dumps(data) instead of just data in requests.post?

    – Upasana Mittal
    Nov 13 '18 at 18:20











  • yes. <Response [403]>

    – Gayan Jeewantha
    Nov 13 '18 at 18:47






  • 2





    It is so strange, i make a same request by py2x and py3x but 2x still returns 403 3x returns 302. The difference is the order of param or encode

    – kcorlidy
    Nov 14 '18 at 8:51








  • 1





    Also i have checked the difference on requests's files, but no difference(i copied py3x module's files to py2x folder but it still responds 403)!

    – kcorlidy
    Nov 15 '18 at 13:16






  • 1





    I even build a simple post function by urllib3, and still gets same result. It seems a very difficult question, because it may associate with standard library.

    – kcorlidy
    Nov 15 '18 at 13:27














  • 1





    have you tried using json.dumps(data) instead of just data in requests.post?

    – Upasana Mittal
    Nov 13 '18 at 18:20











  • yes. <Response [403]>

    – Gayan Jeewantha
    Nov 13 '18 at 18:47






  • 2





    It is so strange, i make a same request by py2x and py3x but 2x still returns 403 3x returns 302. The difference is the order of param or encode

    – kcorlidy
    Nov 14 '18 at 8:51








  • 1





    Also i have checked the difference on requests's files, but no difference(i copied py3x module's files to py2x folder but it still responds 403)!

    – kcorlidy
    Nov 15 '18 at 13:16






  • 1





    I even build a simple post function by urllib3, and still gets same result. It seems a very difficult question, because it may associate with standard library.

    – kcorlidy
    Nov 15 '18 at 13:27








1




1





have you tried using json.dumps(data) instead of just data in requests.post?

– Upasana Mittal
Nov 13 '18 at 18:20





have you tried using json.dumps(data) instead of just data in requests.post?

– Upasana Mittal
Nov 13 '18 at 18:20













yes. <Response [403]>

– Gayan Jeewantha
Nov 13 '18 at 18:47





yes. <Response [403]>

– Gayan Jeewantha
Nov 13 '18 at 18:47




2




2





It is so strange, i make a same request by py2x and py3x but 2x still returns 403 3x returns 302. The difference is the order of param or encode

– kcorlidy
Nov 14 '18 at 8:51







It is so strange, i make a same request by py2x and py3x but 2x still returns 403 3x returns 302. The difference is the order of param or encode

– kcorlidy
Nov 14 '18 at 8:51






1




1





Also i have checked the difference on requests's files, but no difference(i copied py3x module's files to py2x folder but it still responds 403)!

– kcorlidy
Nov 15 '18 at 13:16





Also i have checked the difference on requests's files, but no difference(i copied py3x module's files to py2x folder but it still responds 403)!

– kcorlidy
Nov 15 '18 at 13:16




1




1





I even build a simple post function by urllib3, and still gets same result. It seems a very difficult question, because it may associate with standard library.

– kcorlidy
Nov 15 '18 at 13:27





I even build a simple post function by urllib3, and still gets same result. It seems a very difficult question, because it may associate with standard library.

– kcorlidy
Nov 15 '18 at 13:27












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286484%2fpython27-post-requests-fails%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286484%2fpython27-post-requests-fails%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly