1 year ago

#384314

test-img

connor

Why does my python script fail during a cronjob but works when manually ran?

I'm running a python script that utilizes multiple HTTP GET & POST requests. The first two succeed with no problems, but when I attempt to run the third one through the cronjob I get a HTTP 400 53 error. This is the output my urllib3 log gives me:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.deepai.org:443
DEBUG:urllib3.connectionpool:https://api.deepai.org:443 "POST /api/deepdream HTTP/1.1" 400 53

But when I manually run the script, I get a HTTP 200 None.

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.deepai.org:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.deepai.org:443
DEBUG:urllib3.connectionpool:https://api.deepai.org:443 "POST /api/deepdream HTTP/1.1" 200 None

This is the code my script is running, using the requests python library:

t2iRes = requests.post(
    "https://api.deepai.org/api/text2img",
    data={
        'text': open(filename, 'rb'),
    },
    headers={'api-key': str(APIKey)}
)

Cron Job:

58 20 * * 2 python3 path/to/file/Python-Script.py

If you need any more information about what I'm running or how I'm executing this, please let me know. Thanks!

python

api

http

python-requests

cron

0 Answers

Your Answer

Accepted video resources