pythonboto3grequests

S3 upload fails due to import modules collision


I am using a python script to upload a file to s3 bucket. However I was facing an error like

S3 Upload Failed with exception : An HTTP Client raised an unhandled exception: cannot switch to a different thread

when I investigated, I found strange behavior of packages boto3 and grequests

when I import grequests and boto3 in my script it throws an exception. but same when I remove import grequests from my code the file gets uploaded to s3 with no issues.

import sys, os, time
import grequests
import boto3, ntpath

I really need both grequests and boto3 in my code. but I cannot import grequests if I want to use boto3 for s3 . Is there any way to prevent this behavior?


Solution

  • Looks like a known issue: https://github.com/spyoungtech/grequests/issues/123.

    Solutions suggested in the Github thread include changing order of imports and using an alternative library like https://pypi.org/project/fgrequests/.