Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in requests.post
#4
Have you inspect login (dev-tools Chrome or FireFox),to see what happens when login?
The Form Data most be correct,and you may need a some Header data.
json.dumps(payload) is not needed Requests do serializing automatic as this is build in.

With login there are many different methods and it easy to get stuck.
Requests doc Authentication has some about basic ones,eg Digest, OAuth 1 and 2,OpenId ect...

If i want to log in into this site.
import requests
from bs4 import BeautifulSoup

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}

params = {
    "username": "user_name",
    "password": "xxxxxxxxx",
    "remember": "yes",
    "submit": "Login",
    "action": "do_login",
}

with requests.Session() as s:
    s.post('https://python-forum.io/member.php?action=login', headers=headers, params=params)
    # logged in! cookies get saved for future requests
    response = s.get('https://python-forum.io/index.php')
    # cookies sent automatically!
    soup = BeautifulSoup(response.content, 'lxml')
    welcome = soup.find('span', class_="welcome").text
    print(welcome)
Output:
Welcome back, snippsat. You last visited: Today, 07:29 PM Log Out
Reply


Messages In This Thread
Error in requests.post - by debanilroy - Sep-17-2018, 05:29 PM
RE: Error in requests.post - by volcano63 - Sep-17-2018, 08:41 PM
RE: Error in requests.post - by debanilroy - Sep-18-2018, 05:22 PM
RE: Error in requests.post - by snippsat - Sep-18-2018, 06:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  POST requests - different requests return the same response Default_001 3 2,817 Mar-10-2022, 11:26 PM
Last Post: Default_001
  requests.post() does work Alto 1 2,566 Aug-13-2021, 07:58 AM
Last Post: ndc85430
  Error posting with requests julio2000 6 3,953 Mar-28-2020, 09:43 PM
Last Post: julio2000
  requests issue with post on dot_net api Heinrich 1 2,956 Jan-23-2020, 04:28 AM
Last Post: Larz60+
  Making several POST requests RayeEThompson507 1 3,511 Nov-25-2019, 08:50 PM
Last Post: micseydel
  requests post/get to HTML form mrdominikku 1 2,895 Nov-03-2019, 07:12 PM
Last Post: Larz60+
  error with requests rudolphyaber 9 6,679 May-20-2019, 06:19 PM
Last Post: rudolphyaber
  post data problemHi guys I have small problem in python.I'm getting this error: "PO jure98 4 5,019 Apr-22-2018, 09:33 AM
Last Post: snippsat
  An Error in Requests Module pratheep 3 12,876 Feb-06-2018, 05:17 PM
Last Post: pratheep
  How do i loop through list of data from CSV file and post requests in aspx dynamics w Prince_Bhatia 1 6,787 Nov-09-2017, 02:53 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020