Forums

polling external endpoint outside of flask app with always on

Hi,

I'm trying to poll a an external API to collect data and im getting this error

Dec 10 11:03:11 /home/sirix123/.local/lib/python3.9/site-packages/urllib3/connectionpool.py:981: InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.sdgames.co'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

i'm running it unverified at the moment just trying to get it to work, where is the ssl cert located? i can try and point it to that

code: https://pastebin.com/wtV44FgH

Thanks!

I think I neeed to do something like this r = requests.post(url, data=data, verify='/path/to/public_key.pem') but i dont want to go to the effort to create a custom cert, can i point to the default one?

That should "just work". What if you update your system image? See https://help.pythonanywhere.com/pages/ChangingSystemImage

oh my existing code should just work?

what should i change my system image to?

hi, no errors anymore but it doesn't seem to be running with 'alwayson' i can run the endpoint manually and it works. otherwise though my db never updates and i can't see the alwayson script running

Is your code printing anything? Maybe try adding some logging to the script to see what it's actually doing when running as an always-on task?

Hi,

Yes the code is running

Dec 12 22:10:36 running?
Dec 12 22:10:36 running3
Dec 12 22:11:37 running 2?

def get_poe_account_character_data():
    print("running3", flush=True)
    request = requests.get(f"{APP_URI}/get-poe-account-character-data/{os.environ.get('SECRET_KEY')}")
    logging.log(logging.INFO, f"get_poe_account_character_data: {request.status_code} -> {request.text}")


while True:
    print("running?", flush=True)
    get_poe_account_character_data()
    time.sleep(60)
    print("running 2?", flush=True)

Dec 12 22:34:38 https://www.sdgames.co/scripts/get-poe-account-character-data/None

this might be a problem haha

i wonder why it can't find it, i find it in other files

got it working! thanks for the help, just needed to load the envio vars

Excellent, glad to hear you sorted it out!