Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error for HTTP request GET
#1
When I try to run my script I get a syntax error. Can anyone please tell me what's wrong?

Error:
pi@raspberrypi:~/Desktop $ python TONotificationScript.py File "TONotificationScript.py", line 11 with requests.get('https://tradeogre.com/api/v1/account/balances', auth=HTTPBasicAuth('***', '***') as response: ^ SyntaxError: invalid syntax
(the API keys are not valid)

The whole script is as follows:

import requests
import time
from playsound import playsound

oldData = None

while True:
    with requests.get('https://tradeogre.com/api/v1/account/balances', auth=HTTPBasicAuth('***', '***') as response:
        newData = response.read()
    if oldData is not None and newData != oldData:
        print('Change detected on TO')
        playsound('./Desktop/DEFCON level change.mp3')
        r = requests.post("https://api.pushover.net/1/messages.json", data = {
            "token": "***",
            "user": "***",
            "message": "Change detected on TO"
        },
        )
        print(r.text)
    oldData = newData    
    time.sleep(300)
Reply


Messages In This Thread
Syntax error for HTTP request GET - by THX1138 - May-12-2018, 11:12 AM
RE: Syntax error for HTTP request GET - by snippsat - May-12-2018, 12:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Responding correctly to HTTP request Calab 2 1,152 Apr-14-2023, 04:11 PM
Last Post: Calab
  HTTP 404 error with Session Pool Clives 0 1,285 Jun-17-2021, 06:45 PM
Last Post: Clives
  error HTTP Error 403: Forbidden local_bit 1 2,781 Nov-14-2020, 11:34 AM
Last Post: ndc85430
  How to send unicode string encoded in utf-8 in http request in Python MaverinCode 1 32,353 Nov-08-2020, 06:45 AM
Last Post: JaiM
  urllib.error.HTTPError: HTTP Error 404: Not Found ckkkkk 4 8,631 Mar-03-2020, 11:30 AM
Last Post: snippsat
  python beginner HTTP Error 500 leofcastro 0 2,134 Jan-24-2020, 04:37 PM
Last Post: leofcastro
  Receiving Werkzeug. exception. Bad Request error when using GET with an endpoint robogeek 0 2,627 Jul-02-2019, 01:04 PM
Last Post: robogeek
  HTTP error 404 Karin 4 4,656 May-31-2019, 02:23 PM
Last Post: snippsat
  How to check HTTP error 500 and bypass SriMekala 3 10,373 May-04-2019, 02:07 PM
Last Post: snippsat
  HTTP Header request, how to improve efficiency andreamoro 5 5,056 May-01-2017, 03:49 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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