在postrequest Python之后无法接收jsonresponse

2024-09-30 16:23:44 发布

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

我的任务是从网站页面https://www.dobovo.com/获得一份公寓预订日历。当页面加载时,站点本身接收来自post请求的json格式的数据。当我发送一个类似的请求时,我得到如下错误{'success': False, 'error': 'Method GET is not allowed'},尽管我是用post方法发布请求的。在

有趣的是,几天前我可以用同样的方法得到数据。 有趣的是,我可以从终端获得这个json:curl -d "id=89740&date=2017-07-01" https://www.dobovo.com/dobovo/apt/ajax.php?action=getCalendar&lang=en或{} (id=82731是一个公寓的例子)

我的Python代码:

from requests import post
def get_calendar(url):
    ajax = 'http://www.dobovo.com/dobovo/apt/ajax.php?action=getCalendar&lang=en'
    first_day_in_month = '2017-07-01'
    id_ = url[-10:-5]
    form_data = {
        'id': id_,
        'date': first_day_in_month
    }
    response = post(url=ajax, data=form_data)
    return response.json()

这里的url是指向带有日历的页面的链接,如https://www.dobovo.com/zaporozhye-apartments/orchid-82731.html

请告诉我,我做错什么了?在


Tags: 数据方法httpscomidjsonurldata