A story that didn't work when I tried to log in with the Python requests module

problem

Looking at various reference articles (Qiita login etc.), for the login page

payload = {
    'userid': 'my_id',
    'password': 'my_pass'
}
s = requests.Session()
p = s.post(login_url, data=payload)

r = s.get(want_to_access_url)

It's been processed like this, and it works! I heard that, but for some reason I can't log in to the page I wanted to log in to ...

If I try it with excite mail, it works ...

Solution

If you read the source code carefully, you will see the upper part of the login form.

<form action="/login/login/" method="post">

There was such a code.

Try google

** What is action attribute **? -It must be specified in the attribute specified in the form tag. -Press the submit button of the form and specify the destination of the data to be submitted ・ The destination of data is called URI -Specify the URI of the CGI program of the server that handles the data transfer process.

So ** Just rewrite the end of the URL to the action path! ?? ** **

add-action-path


failed_url = 'https://ssl.syosetu.com/login/input/'  #URL displayed when accessed from a browser
success_url = 'https://ssl.syosetu.com/login/login/'  #URL where you can log in successfully

I tried it and it worked well with Don Pisha.

I have to study the WEB ... Sweat

If you think "Oh? I can't log in! Why!", Please try it!

Recommended Posts

A story that didn't work when I tried to log in with the Python requests module
When I tried to create a virtual environment with Python, it didn't work
I want to work with a robot in python.
A story that I was addicted to when I made SFTP communication with python
[Python] A memo that I tried to get started with asyncio
I tried to improve the efficiency of daily work with Python
The story of making a module that skips mail with python
A story that went missing when I specified a path starting with a tilde (~) in python open
I also tried to imitate the function monad and State monad with a generator in Python
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
When I tried to create a project using Python on Docker with PyCharm, it didn't work, but it worked with Docker Compose.
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
I tried to develop a Formatter that outputs Python logs in JSON
I tried adding a Python3 module in C
Create a record with attachments in KINTONE using the Python requests module
I tried to create a class that can easily serialize Json in Python
I tried to predict the horses that will be in the top 3 with LightGBM
I want to see a list of WebDAV files in the Requests module
I tried to graph the packages installed in Python
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to implement a pseudo pachislot in Python
I tried to automatically generate a password with Python3
A memo that I touched the Datastore with python
I tried to solve the problem with Python Vol.1
Work memo that I tried i18n with Flask app
A story that I did not know how to load a mixin when making a front with the django app [Beginners learn python with a reference book in one hand]
[Python & SQLite] I tried to analyze the expected value of a race with horses in the 1x win range ①
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
Introduction to AI creation with Python! Part 2 I tried to predict the house price in Boston with a neural network
I tried to find out how to streamline the work flow with Excel x Python ②
A story that failed when trying to remove the suffix from the string with rstrip
I tried to find out how to streamline the work flow with Excel x Python ④
A story that got stuck when trying to upgrade the Python version on GCE
I tried to find out how to streamline the work flow with Excel x Python ⑤
I got stuck when trying to specify a relative path with relative_to () in python
I tried to find out how to streamline the work flow with Excel x Python ①
A memo of misunderstanding when trying to load the entire self-made module with Python3
I tried to find out how to streamline the work flow with Excel x Python ③
A story that stumbled when I made a chatbot with Transformer
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
I tried to implement a one-dimensional cellular automaton in Python
The story that `while queue` did not work in python
I tried "a program that removes duplicate statements in Python"
I tried "How to get a method decorated in Python"
I tried to implement the mail sending function in Python
I can't log in to the admin page with Django3
I tried to make a stopwatch using tkinter in python
I tried to divide the file into folders with Python
[1 hour challenge] I tried to make a fortune-telling site that is too suitable with Python
I made a class to get the analysis result by MeCab in ndarray with python
I made a program to collect images in tweets that I liked on twitter with Python
I tried to make a generator that generates a C # container class from CSV with Python
The story I was addicted to when I specified nil as a function argument in Go
I tried to make a function to judge whether the major stock exchanges in the world are daylight saving time with python
[5th] I tried to make a certain authenticator-like tool with python
I tried to describe the traffic in real time with WebSocket
I want to use a wildcard that I want to shell with Python remove
[2nd] I tried to make a certain authenticator-like tool with python
A memorandum when I tried to get it automatically with selenium