Using 'Requests' python module for POST request, receiving response as if it were GET

Viewed 588

So I am trying to make a script that checks a reservation availability of a bus. The starting link for this is https://reservation.pc.gc.ca/.

In the reserve box the following needs to be selected:

  • Reservation: Day Use (Guided Hikes, Lake O’Hara Bus)
  • Park: Yoho-Lake O'Hara
  • Arrival Date: Jun 16
  • Party Size: 2

When those options are entered, it takes you to the following page: https://reservation.pc.gc.ca/Yoho-LakeO'Hara?Calendar

It is my understanding that if I send a POST request to that second link with the correct data it should return the page I'm looking for

If I look in the dev tools network info when I select the correct parameters the form data is:

__EVENTTARGET:

__EVENTARGUMENT: __VIEWSTATE: -reallllly long string-

__VIEWSTATEGENERATOR: 8D0E13E6

ctl00$MainContentPlaceHolder$rdbListReservationType: Events

ddlLocations: 213a1bc9-9218-4e98-9a7f-0f209008e437**

ddlArrivalMonth: 2017-06-16

ddlArrivalDay: 19

ddlNights: 1

ddlDepartureMonth:

ddlDepartureDay:

ddlEquipment:

ddlEquipmentSub:

ddlPartySize:2

ctl00$MainContentPlaceHolder$chkExcludeAccessible: on

ctl00$MainContentPlaceHolder$imageButtonCalendar.x: 64

ctl00$MainContentPlaceHolder$imageButtonCalendar.y: 56

So the code I wrote is:

import requests

payload = {
        '__EVENTTARGET': '',
        '__EVENTARGUMENT': '',
        '__VIEWSTATE':-reallly long string-,
        '__VIEWSTATEGENERATOR': '8D0E13E6',
        'ctl00$MainContentPlaceHolder$rdbListReservationType': 'Events',
        'ddlLocations': '213a1bc9-9218-4e98-9a7f-0f209008e437',
        'ddlArrivalMonth': 2017-06-16,
        'ddlArrivalDay': 19,
        'ddlNights': 1,
        'ddlDepartureMonth': '',
        'ddlDepartureDay': '',
        'ddlEquipment': '',
        'ddlEquipmentSub': '',
        'ddlPartySize': 2,
        'ctl00$MainContentPlaceHolder$chkExcludeAccessible': 'on',
        'ctl00$MainContentPlaceHolder$imageButtonCalendar.x': 64,
        'ctl00$MainContentPlaceHolder$imageButtonCalendar.y': 56
        }

r = requests.get(r"https://reservation.pc.gc.ca/Yoho-LakeO'Hara?Calendar", data=payload)

print r.text

r.text ends up just being the second link as if no parameters were entered - as if I just sent a normal GET request to the link. I tried turning the payload values that are integers into strings, I tried removing the empty key:value pairs. No luck. Trying to figure out what I'm missing.

2 Answers
Related