Curl可以,但是Python请求不行

2024-09-25 06:31:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试建立一个机器人,可以自动安排学校的会议室。目前有一个网站处理这个,但它是非常乏味的。我能够得到最小的CURL命令来成功地进行这些预订。但是,当我切换到使用python请求时,会出现一个错误,比如我预订了太多的站点。但是,如果我在它之后运行相同的curl命令,则没有错误。我认为HTTP请求有问题,但我不知道从哪里开始。在

卷曲:

    curl 'https://api3.libcal.com/process_roombookings.php?m=booking_mob&iid=1723' \
-XPOST \
-H 'Referer: https://api3.libcal.com/room_widget.php?gid=4066&iid=1723' \
--data 'gid=4066&sid%5B%5D=660065516&fname=<First Name>&lname=<Last Name>&email=<School Email>&q1=<Student ID>&q2=4-6&q3=Engineering&q4=CPE&qcount=4&fid=2166'

Python请求:

^{pr2}$

卷曲输出:

{"status":2,"msg":"<div class=\"alert alert-warning\"><p><strong>This booking is tentative only!<\/strong><\/p><p><span class='rm_book_tent'>Room I, 12:00am - 1:00am Friday, February 15, 2019 - Tentative<\/span><br\/><\/p><p>You must confirm the booking within 1 hour,  via the URL contained in the email just sent to you.<\/p><\/div>","type":""}

Python请求输出:

{'status': 2, 'msg': '<div class="alert alert-danger"><p><strong>You have exceeded the booking limits/quota:</strong></p><p></p><p></p></div>', 'type': ''}

卷曲将返回与原始卷相同的值。所以只有当我使用请求时,我才会认为这是其他错误。在

你知道为什么一个人返回一个网站(状态=200)时出现错误而不是预订吗?在

附言:这个问题我已经问过几次了,但大多数都是关于授权的问题。我的感觉完全不同。在


Tags: thehttps命令divcom网站错误alert
1条回答
网友
1楼 · 发布于 2024-09-25 06:31:55

我尝试了curl和requests,得到了相同的错误消息({“status”:0,“msg”:“error-No user data submitted”,“type”:“”},下面是我使用请求的代码:

import requests

headers = {
    'Referer': 'https://api3.libcal.com/room_widget.php?gid=4066&iid=1723',
}

params = (
    ('m', 'booking_mob'),
    ('iid', '1723'),
)

data = {
  'gid': '4066',
  'sid[]': '660065516',
  'fname': '<First Name>',
  'lname': '<Last Name>',
  'email': '<School Email>',
  'q1': '<Student ID>',
  'q2': '4-6',
  'q3': 'Engineering',
  'q4': 'CPE',
  'qcount': '4',
  'fid': '2166'
}

response = requests.post('https://api3.libcal.com/process_roombookings.php', headers=headers, params=params, data=data)

相关问题 更多 >