0

I'm trying to get the lat long coordinates of known land parcels using a government land locater app. The website is www.makani.ae

Say I input land number "3520461" into the search field and search for it. I'm trying to replicate the post requests as such:

import requests

url = 'https://www.makani.ae/makaniproxy/Makani.svc/getmakanidatanew'

headers = {
            "Host": "www.makani.ae",
            "Connection": "keep-alive",
            "Content-Length": "291",
            "Accept": "application/json, text/javascript, */*; q=0.01",
            "Origin": "http://www.makani.ae",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36",
            "Content-Type": "application/json;charset=UTF-8",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Referer": "http://www.makani.ae/desktop/index.html?25",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "en-US,en;q=0.9"
            }
payload = {
            'parameters': {
                            'InputJson': {
                                            'searchtext': '3520461',
                                            'lang': 'E',
                                            'currentlocation': '25.26452971,55.31196410',
                                            'distancetype': 'KM',
                                            'level': '2',
                                            'userid': '',
                                            'sessionid': ''},
                            'Token': 'b7s5isip5p6nkrenhfbd9bdbg8!=+=BDEE6d4K4CL6nplm720bIA==',
                            'Remarks': 'Makani Phase 2'},
            'url': 'http://www.makani.ae/MakaniPhase2ProxyWebService/MakaniPhase2Proxy.svc/SmartSearch'
            }

r = requests.post(url,data=payload, headers=headers)

This returns a 400 error. Where am I going wrong?

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
sjp_1989
  • 137
  • 4

2 Answers2

0

Your headers looks a bit off. I would recommend replacing your current headers with this one:

headers = {
            "Accept": "application/json, text/javascript, */*; q=0.01",
            "Origin": "http://www.makani.ae",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36",
            "Content-Type": "application/json;charset=UTF-8",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Referer": "http://www.makani.ae/desktop/index.html?25",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "en-US,en;q=0.9"
            }

Hope this helps

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
0

I realized that the issue was with the nested dictionary in my payload variable. Credits to https://stackoverflow.com/a/57999804. Working code below:

import requests
import json

url = 'https://www.makani.ae/makaniproxy/Makani.svc/getmakanidatanew'

headers = {
            "Host": "www.makani.ae",
            "Connection": "keep-alive",
            "Content-Length": "291",
            "Accept": "application/json, text/javascript, */*; q=0.01",
            "Origin": "http://www.makani.ae",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36",
            "Content-Type": "application/json;charset=UTF-8",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Referer": "http://www.makani.ae/desktop/index.html?25",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "en-US,en;q=0.9"
            }
payload = {
            'parameters': {
                            'InputJson': {
                                            'searchtext': '3520461',
                                            'lang': 'E',
                                            'currentlocation': '25.26452971,55.31196410',
                                            'distancetype': 'KM',
                                            'level': '2',
                                            'userid': '',
                                            'sessionid': ''},
                            'Token': 'b7s5isip5p6nkrenhfbd9bdbg8!=+=BDEE6d4K4CL6nplm720bIA==',
                            'Remarks': 'Makani Phase 2'},
            'url': 'http://www.makani.ae/MakaniPhase2ProxyWebService/MakaniPhase2Proxy.svc/SmartSearch'
            }

r = requests.post(url,data=json.dumps(payload), headers=headers)
sjp_1989
  • 137
  • 4