'Bad gate way Error while using ftp in server

Actually we are using python3.6.8 in our server, we are trying to connect the ftp server and pushing files to the ftp server through an api call, here when we try to push the files from local it is running fine and files are being pushed but when calling api to the server it is redirecting to a 502 bad gateway error after 14.8s time when tried with postman. the server we use is AWS EC2

        ftp = ftplib.FTP()
        host = config.FTP_HOST
        port = 21
        ftp.connect(host, port)
        try:
            ftp.login(config.FTP_USERNAME, config.FTP_PASSWORD)
            file = open(path_image, 'rb')
            ftp.cwd("/DailyDump/target/")
            ftp.storbinary("STOR sample_file_name" + str(yesterday_date) + ".csv", file)
            file.close()
            ftp.close()

        except:
            pass


Solution 1:[1]

This problem was caused due to the maximum timeout reached on the API call, hence I transferred the codes from API to stand alone code to make it run for longer time period without giving error. so there is no error in ftp logging.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Surya R