# Python API not working

**URL:** <https://discuss.python.org/t/python-api-not-working/13602>\
**Category:** Python Help\
**Tags:** help\
**Created:** [February 9, 2022, 6:51am UTC](https://discuss.python.org/t/python-api-not-working/13602 "2022-02-09T06:51:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paarth-go](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/paarth-go/32/6178_2.png) [@Paarth-go](https://discuss.python.org/u/Paarth-go)\
**Post date:** [February 9, 2022, 6:51am UTC](https://discuss.python.org/t/python-api-not-working/13602/1 "2022-02-09T06:51:20Z")

</div>

Hi, I am trying to fetch API response.  
It’s not coming:  
Code:

```auto
import requests
import json
lat = 17.5901322
lng = 78.491586
parameters = {
    "point": str(lat) + "%2C" + str(lng) + "&point=" + "17.3850442%2C78.486671",
    "locale": "en-us",
    "elevation": "true",
    "profile": "car",
    "use_miles": "false",
    "selected_detail": "Elevation",
    "layer": "Omniscale",
    "key": "I won't keep the key here"
}
response = requests.get("https://graphhopper.com/api/1/route", params=parameters)
def jprint(obj):
    text = json.dumps(obj, sort_keys=True, indent=4)
    print(text)

jprint(response.json())

```

Resopnse:

```auto
{
    "message": "Specify at least 2 points"
}

```

When I send through the Browser:

```auto
(https://graphhopper.com/api/1/route?point=17.590132%2C78.491586&point=17.385044%2C78.486671&locale=en-us&elevation=true&profile=foot&use_miles=false&selected_detail=Elevation&layer=Omniscale&key=i won't give here)

```

Here I am getting the response

---

<div class="post-metadata">

**Author:** ![frostming](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/frostming/32/326_2.png) [@frostming](https://discuss.python.org/u/frostming)\
**Post date:** [February 9, 2022, 7:00am UTC](https://discuss.python.org/t/python-api-not-working/13602/2 "2022-02-09T07:00:40Z")

</div>

> [@Paarth-go](#):
>
> ```auto
> parameters = {
> "point": str(lat) + "%2C" + str(lng) + "&point=" + "17.3850442%2C78.486671",
> "locale": "en-us",
> "elevation": "true",
> "profile": "car",
> "use_miles": "false",
> "selected_detail": "Elevation",
> "layer": "Omniscale",
> "key": "I won't keep the key here"
> }
> 
> ```

Let `requests` encode the params for you instead of building the string by hand:

```auto
parameters = {
    "point": [f"{lat},{lng}", "17.3850442,78.486671"],
    "locale": "en-us",
    "elevation": "true",
    "profile": "car",
    "use_miles": "false",
    "selected_detail": "Elevation",
    "layer": "Omniscale",
    "key": "I won't keep the key here"
}

```

BTW for a question related to a specific service or tool, it would be better to be raised on StackOverflow or the bug tracker of that tool.

---

<div class="post-metadata">

**Author:** ![Paarth-go](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/paarth-go/32/6178_2.png) [@Paarth-go](https://discuss.python.org/u/Paarth-go)\
**Post date:** [February 9, 2022, 7:02am UTC](https://discuss.python.org/t/python-api-not-working/13602/3 "2022-02-09T07:02:42Z")

</div>

Thanks a lot it worked like a charm!
