简体   繁体   English

为什么我的 Python POST 请求会引导我进入初始网页?

[英]Why does my Python POST request lead me to the initial webpage?

I am new to this Forum and relatively new to coding我是这个论坛的新手,对编码也比较陌生

This question has already been asked here but the solutions didn't seem to work for me.这个问题已经在这里问过了,但解决方案似乎对我不起作用。

I'd like to log into the index.php page using a Python Post request, but the response url remains the same with the intitial login page indicating that the login was not successful.我想使用 Python 发布请求登录 index.php 页面,但响应 url 仍然与初始登录页面相同,表明登录不成功。

import requests as r

login_url = "https://www.example.com/index.php?login"
index_url = "https://www.example.com/gymla/index.php" #The url I want to be directed to

data = {
    "isiwebuserid": "username",
    "isiwebpasswd": "password",
    "submit": "Senden"
}

s = r.session()
response = s.post(login_url, data=data)

print(response.url)
if response.url == login_url:
    print("The attempt did not work.")

I've checked with <form action if the login URL might be wrong, but it seems alright.如果登录 URL 可能是错误的,我已经检查了 <form action,但它似乎没问题。 The form data is also complete.表格资料也齐全。 What else could be wrong?还有什么可能是错的?

Url does not change but remains fixed, Try this Url 不改变但保持固定,试试这个

if response.status_code != 200:
    print("The attempt did not work.")

Thank you guys for answering my question.谢谢你们回答我的问题。 The solution was indeed to use "Submit" instead of "Senden" .解决方案确实是使用"Submit"而不是"Senden"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么这个 curl 命令有效,但我通过 python 发出的请求无效? - Why does this curl command work but not my post request via python? 为什么我的 python 服务器将 post 请求数据保存到数据库中为“0”? - Why does my python server save the post request data to the database as “0”? 为什么我的 python POST 请求无法收集我想要的信息? - Why does my python POST request fails to gather the info I want? 为什么这个 Python POST 请求返回 400 Bad Request Code? - Why does this Python POST Request returns 400 Bad Request Code? 为什么我的 Django request.method 是“GET”而不是“POST”? - Why does my Django request.method is 'GET' not 'POST'? python-为什么我的程序告诉我它不可调用 - python- why does my program tells me it's not callable 为什么python告诉我我的yes变量未定义? - why does python tell me that my yes variable not defined? 有人可以帮我解决关于我在 python 中的 API 的发布请求的错误吗? - Can someone help me with an error about my post request for my API in python? 为什么HTTP POST请求体需要在Python中加入JSON? - Why does HTTP POST request body need to be JSON enconded in Python? 为什么无法将此Python POST请求转换为Java? - Why does converting this Python POST request to Java not work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM