Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of respond.get
#1
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)
Reply
#2
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).
ebolisa likes this post
Reply
#3
(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!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make a telegram bot respond to the specific word in a sentence? Metodolog 2 4,719 Dec-22-2020, 07:30 AM
Last Post: martabassof
  if-loop does not respond to input Kmarstein 1 1,620 Jan-28-2020, 09:29 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020