I'm trying to make a Python script to log into Twitter with requests (through another site) based on a PHP script that I made that worked. But throw the next error
Traceback (most recent call last): File "C: /Users/User/Desktop/instabot-twitbot/logueo_twitter.py", line 51, in login = s.post (url_login, data = login_post, allow_redirects = True) File "C: \ Python27 \ lib \ site-packages \ requests \ sessions.py", line 555, in post return self.request ('POST', url, data = data, json = json, ** kwargs) File "C: \ Python27 \ lib \ site-packages \ requests \ sessions.py", line 508, in request resp = self.send (prep, ** send_kwargs) File "C: \ Python27 \ lib \ site-packages \ requests \ sessions.py", line 640, in send history = [resp for resp in gen] if allow_redirects else [] File "C: \ Python27 \ lib \ site-packages \ requests \ sessions.py", line 140, in resolve_redirects raise TooManyRedirects ('Exceeded% s redirects.'% self.max_redirects, response = resp) TooManyRedirects: Exceeded 30 redirects.
The code is as follows
import requests
s = requests.Session()
## Cambiar usuario y password!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#url= "https://twiends.com/oauth/twitter"
url = "https://twitter.com/login"
url_login = "https://twitter.com/sessions"
user_login = "usuario"
user_password = "password"
user_agent = ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36")
accept_language = 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4'
response = s.get(url)
posicion_token = response.text.find("authenticity_token")
print "El token es"
print response.text[posicion_token+27:posicion_token+67]
##print response.text[posicion_token+41:posicion_token+81]
token = response.text[posicion_token+41:posicion_token+79]
##token = response.text[posicion_token+41:posicion_token+81]
login_post = {'session[username_or_email]' : user_login,
'session[password]' : user_password,
'return_to_ssl':'true',
'scribe_log':'',
'redirect_after_login':'%2F',
'authenticity_token':token
}
print login_post
s.headers.update ({'Accept-Encoding' : 'gzip, deflate',
'Accept-Language' : accept_language,
'Connection' : 'keep-alive',
'Content-type': 'application/x-www-form-urlencoded',
'Host' : 'www.twitter.com',
'Origin' : 'https://www.twitter.com',
'Referer' : 'https://www.twitter.com/',
'User-Agent' : user_agent
})