“Connect timeout on endpoint URL” when running cron job

假如想象 提交于 2021-01-29 08:54:26

问题


I have set a crontab file to run a Python script that creates an JSON file and writes it to an S3 bucket. It runs as expected when executed from the command line, but when I run it as a cron job, I get the following error:

botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint URL

This results from the following lines of code in the script:

import boto3

def main():
    # Create EC2 client and get EC2 response
    ec2 = boto3.client('ec2')
    response = ec2.describe_instances()

My guess is that some permission is not set in the cron job, denying me access to the URL.


回答1:


It turns out that I had to set the proxy settings so I access AWS as myself rather than root. I ran the cron job as a Linux shell script rather then a Python script, and exported my http_proxy, https_proxy, and no_proxy settings found in ~/.bash_profile in the first lines of the shell script

`export http_proxy=<http_proxy from ~/.bash_profile>
 export https_proxy=<https_proxy from ~/.bash_profile>
 export no_proxy=<no_proxy from ~./bash_profile>
 python <python script>`


来源:https://stackoverflow.com/questions/59397508/connect-timeout-on-endpoint-url-when-running-cron-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!