I am trying to make a POST with some data and the cookies received before with a GET. I had a code with PyCurl that works correctly but I need to use Requests. However, the using Request does not work although I am doing the same steps. The working code on PyCurl is:
import time
import urllib
import pycurl
curl = pycurl.Curl()
curl.setopt(pycurl.URL, 'https://www.myURL.com/header?time='+str(int(time.time())))
curl.setopt(pycurl.COOKIEJAR, 'cookie_1.txt')
curl.perform()
curl.close()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, 'https://www.myURL.com/login')
post_data = {'actualURL': 'http://www.myURL.com', 'user': 'myemail@gmail.com', 'pass': 'asdfqwerty'}
curl.setopt(pycurl.COOKIEFILE, 'cookie_1.txt')
curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(post_data))
curl.setopt(pycurl.COOKIEJAR, 'cookie_2.txt')
curl.perform()
curl.close()
I receive in 'cookie_2.txt' file the correct answer with new data on cookies. However, as said before, the following code give me a response of Error 403
import time
import urllib
import requests
r1 = requests.get('https://www.myURL.com/header?time='+str(int(time.time())))
payload = {'actualURL': 'http://www.myURL.com', 'user': 'myemail@gmail.com', 'pass': 'asdfqwerty'}
r2 = requests.post('https://www.myURL.com/login', data=urllib.urlencode(payload), cookies=r1.cookies)
As you can see, I use the same cookies received from previous request as mentioned here. I checked 'r1.cookies' and are set correct. Also, as POST data has special characters I used an encoding from urllib (PyCurl does not work without this).
I firstly thought that the problem on 'Requests' comes from special characters on POST data, but I have tried with encoding, without encoding, as a json string,... but nothing works. 'r2.cookies' is empty