Trying to use GET on a weather api but python keeps adding a questionmark
<p>So I wanted to try some things out with a weather api but I can't seem to get it working. When I run the code, the Python interpreter keeps adding a questionmark to my request so I just get a 404 response, not found.</p>

<p>This is my code:</p>

<pre><code>import requests
from requests.auth import HTTPDigestAuth
import json
url = "http://opendata-download-metfcst.smhi.se"

myResponse = requests.get(url,"api/category/pmp2g/version/2/geotype/point/lon/16.158/lat/58.5812/data.json", verify=True)

if(myResponse.ok):
    jData = json.loads(myResponse.content)
    print("The response contains {0} properties".format(len(jData)))
    print("\n")
    for key in jData:
        print (key + " : " + jData[key])
else:
     myResponse.raise_for_status()
</code></pre>

<p>And this is my error message:</p>

<pre><code>requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://opendata-download-metfcst.smhi.se/?/category/pmp2g/version/2/geotype/point/lon/16.158/lat/58.5812/data.json
</code></pre>

<p>As you can see it replaces the beginning of the request "api" with a questionmark. This is why it can't find the resource. Why does it do this?</p>

<p>Try to use:</p>

<pre><code>myResponse = requests.get("{}/api/category/pmp2g/version/2/geotype/point/lon/16.158/lat/58.5812/data.json".format(url))
</code></pre>

<p>Currently you're passing the rest of URL as GET params.</p>

<p>From <code>requests</code> docs:</p>

<pre><code>&gt;&gt;&gt; payload = {'key1': 'value1', 'key2': 'value2'}
&gt;&gt;&gt; r = requests.get('http://httpbin.org/get', params=payload)
</code></pre>

<p>You can see that the URL has been correctly encoded by printing the URL:</p>

<pre><code>&gt;&gt;&gt; print(r.url)
http://httpbin.org/get?key2=value2&amp;key1=value1
</code></pre>

python api request