Python Forum

Full Version: Use of respond.get
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'd like to read the response from a web page by sending this url: "https://mypage.com/get.php?api_key=0123456789". When done from a browser, the link works and I get data from the server.

However, when using the following code, I get an error from the web server: "wrong key".

I appreciate some insides.
TIA

# importing the requests library
import requests

# defining the api-endpoint
URL = "https://mypage.com/get.php"

# your API key here
API_KEY = '0123456789'

# data to be sent to api
data = {'api_key': API_KEY}

# sending post request and saving response as response object
r = requests.get(URL)
if r:
    r = requests.get(url = URL, data = data)

    # extracting response text
    url_response = r.text
    print("The response from URL is:%s" % url_response)
If you need to send query parameters in the request, then use the params argument to get, not data (docs here: https://docs.python-requests.org/en/late...ts.request).
(Jul-31-2021, 02:08 PM)ndc85430 Wrote: [ -> ]If you need to send query parameters in the request, then use the params argument to get, not data (docs here: https://docs.python-requests.org/en/late...ts.request).
Wall Thank you!!