0

My task is to get a calendar of booking of apartments from the site pages https://www.dobovo.com/ . The site itself receives data from the post-request in json format when the page is loaded. When I send a similar request, I get the following error {'success': False, 'error': 'Method GET is not allowed'}, although I post the request by the post method.

Interestingly, a few days ago I could get the data in the same way. It's also funny that I can get this json from the terminal: curl -d "id=89740&date=2017-07-01" https://www.dobovo.com/dobovo/apt/ajax.php?action=getCalendar&lang=en or wget --post-data="id=82731&date=2017-07-01" https://www.dobovo.com/dobovo/apt/ajax.php?action=getCalendar&lang=en (id = 82731 is an example for one apartment)

My Python code:

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 here is a link to a page with a calendar, like https://www.dobovo.com/zaporozhye-apartments/orchid-82731.html

Tell me, please, what am I doing wrong?

  • take a look at your `ajax` variable, that URL doesn't even return a valid response – gold_cy Jul 10 '17 at 18:27
  • @aws_apprentice This is the URL of the request. It can not return anything unless you send a post-request with data. And this URL is correct, since I send requests to it from the terminal and get the necessary data. Or I do not understand you? – Denis Ignashov Jul 10 '17 at 18:35
  • You have to use `requests.Session` for this task. – t.m.adam Jul 11 '17 at 10:13

0 Answers0