0
    POST /somelink
    Host: hostname
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101
    Firefox/47.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate, br
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 683
    Cookie: xxx
    Connection: keep-alive
    access_token=xxx

How can I form an api call with these details? I already tried:

payload={ "POST":"somelink",
                         "Host":"hostname",
                         "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0",
                         "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                         "Accept-Language":"en-US,en;q=0.5",
                         "Accept-Encoding":"gzip, deflate, br",
                         "Content-Type": "application/x-www-form-urlencoded",
                         "Content-Length": "683",
                         "Cookie":" xxx",
                         "Connection":"keep-alive",
                         "access_token":"xxx"}
                headers = {}
                r = requests.post(url, data=json.dumps(payload), headers=headers)

But if I try this way I get 'Connection aborted.', gaierror(-2, 'Name or service not known'. Can anyone help me with this ?

Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
Nikhilsome
  • 23
  • 5
  • Possible duplicate of [What does this socket.gaierror mean?](https://stackoverflow.com/questions/15246088/what-does-this-socket-gaierror-mean) – solarissmoke May 10 '18 at 10:18
  • What is your `url`? Where are you running this? Are you able to do a `nslookup` from the machine that is hosting this code to the `url` that is needed? – rtindru May 10 '18 at 10:19

1 Answers1

0

gaierror means that the DNS lookup is failing: What does this socket.gaierror mean?

Which means Python is unable to resolve the host name to an IP address to initiate the request. Example:

>>> from socket import gethostbyname
>>> gethostbyname('www.google.com')
'172.217.26.196'
>>> gethostbyname('www.wrongurlthatdoesnotexist.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
Zoe
  • 27,060
  • 21
  • 118
  • 148
rtindru
  • 5,107
  • 9
  • 41
  • 59