Variable in S3 Proxy Server Verbindung mit Boto3

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
dugjibe
User
Beiträge: 2
Registriert: Donnerstag 9. November 2017, 10:30

Hi,
I want to use the IP and Port as Variables in my S3 Proxy Server Connect command using the boto3 module.

This is the Python AWS S3 connect, which works fine:

s3client = boto3.resource(
's3',
aws_access_key_id = args.AWS_ACCESS_KEY_ID,
aws_secret_access_key=args.AWS_SECRET_ACCESS_KEY,
config=Config(proxies={'https': '192.168.88.1:3128'}),
)

I want to use the same AWS S3 connection, but with IP and Port as Variables (e.g. args.proxy, args.port).
This is what I want to achieve:

s3client = boto3.resource(
's3',
aws_access_key_id = args.AWS_ACCESS_KEY_ID,
aws_secret_access_key=args.AWS_SECRET_ACCESS_KEY,
config=Config(proxies={'https': 'args.proxy: args.port'}),
)
dugjibe
User
Beiträge: 2
Registriert: Donnerstag 9. November 2017, 10:30

Hi,
I solved it:

s3client = boto3.resource(
's3',
aws_access_key_id = args.AWS_ACCESS_KEY_ID,
aws_secret_access_key=args.AWS_SECRET_ACCESS_KEY,
#before: config=Config(proxies={'https': '192.168.88.1:3128'}),
config=Config(proxies={'https': '%s:%s' % (args.proxy, args.port)})
)
Benutzeravatar
sls
User
Beiträge: 480
Registriert: Mittwoch 13. Mai 2015, 23:52
Wohnort: Country country = new Zealand();

Hi dugjibe,

Code: Alles auswählen

config=Config(proxies={'https': 'args.proxy: args.port'})
'args.proxy: args.port' is just one String though. It should rather look like:

Code: Alles auswählen

{'https': "{0}:{1}".format(proxy_ip, proxy_port)}
Oh, too late. Anyways, aforementioned solution uses the format()-function.

Cheers, sls
When we say computer, we mean the electronic computer.
Antworten