Sean Iffland
Sean Iffland

Reputation: 29

Passing a variable to params with python requests.get

I am currently sending an api request and am using the following params:

params = (
    ('adminDeviceSpaceId', '1'),
    ('fields', 'special.field'),
    ('query', 'user.email_address="[email protected]"'),
)

requests.get works fine, i need to replace the email with a variable (passed in from another program). When i replace the email= with

EMAIL_VARIABLE = '[email protected]'
('query', 'user.email_address="(EMAIL_VARIABLE)"'),

it does not work, tried every permutation of removing and changing quotes. Has to be something simple.

It is on RHEL7 so it is python 2.7.5.

Upvotes: 0

Views: 169

Answers (2)

DeveloperLV
DeveloperLV

Reputation: 1781

For anyone using Python 3

https://realpython.com/python-f-strings/

f"user.email_address={EMAIL_VARIABLE}"

Usage :

>>> print(f'user.email_address={EMAIL_VARIABLE}')
[email protected]

Python 2.7

print 'user.email_address={}'.format(EMAIL_VARIABLE))

or

print 'user.email_address={0}'.format(EMAIL_VARIABLE))

https://pyformat.info/#simple

Upvotes: 1

jdaz
jdaz

Reputation: 6043

In Python 2.7 you can use:

'user.email_address="{}"'.format(EMAIL_VARIABLE)

Upvotes: 4

Related Questions