1

How can I send this curl out using Python? I did find similar requests, but cannot adapt my code to suite the query I have also tried using pycurl, following this example but without luck.

$ curl -v -X GET  -H "Accept: text/csv" -H "Authorization: Basic YW5kcmVhLmJvdHRpQHdzcC5jb206OWY5N2E5YTY2ZWU1MTMxZjdmNjk4MDcwZTFkODEwMjU0M2I0NTg1ZA==" "https://epc.opendatacommunities.org/api/v1/domestic/search"

Thanks

Andreuccio
  • 1,053
  • 2
  • 18
  • 32
  • Possible duplicate of [adding header to python requests module](https://stackoverflow.com/questions/8685790/adding-header-to-python-requests-module) – Diptangsu Goswami Sep 04 '19 at 10:45

1 Answers1

2

If you are using the Python Requests package the following code snippet should work:

import requests

headers = {
    'Accept': 'text/csv',
    'Authorization': 'Basic YW5kcmVhLmJvdHRpQHdzcC5jb206OWY5N2E5YTY2ZWU1MTMxZjdmNjk4MDcwZTFkODEwMjU0M2I0NTg1ZA==',
}

response = requests.get('https://epc.opendatacommunities.org/api/v1/domestic/search', headers=headers)

response.status_code  # 200
response.text # "lmk-key,address1,address2,address3,postcode,buildi ..."

(Note: I used the https://curl.trillworks.com/ website to automatically make the conversion)

Bob
  • 1,004
  • 9
  • 12