ITHelpGuy
ITHelpGuy

Reputation: 1047

encrypt credentials making rest api get method call

I am using the below code to read response from an api. I am stuck with how to encrypt credentials. I get invalid syntax error.

import requests
from base64 import b64encode

user = "usr"
password = "pwd"

response = requests.get('https://myapi/v1/api',
                        auth=(user, password) # invalid syntax
data = response.json()

Upvotes: 0

Views: 113

Answers (2)

JarroVGIT
JarroVGIT

Reputation: 5359

You are missing a parenthesis in this line at the end:

response = requests.get('https://myapi/v1/api', auth=(user, password))

Upvotes: 1

Code-Apprentice
Code-Apprentice

Reputation: 83567

I am using the below code to read response from an api. I am stuck with how to encrypt credentials.

https already encrypts the request, so you don't need to do anything special here.

I get invalid syntax error.

You get this error because you are missing a closing parenthese.

Upvotes: 0

Related Questions