Uncategorized

Concatenating Strings causing issues in Python


I am facing kind of weird issue in Python related to concatenating the strings.
We have a requirement where we need to connect to external data source through API and extract the data. While connecting through API we need to pass various credentials as part of raw_data in form of a string like below example (This is not actual credentials but use as an example).

raw_data="client_id=JWElPOC1XaR4NkldTaXsWGTzJsQ5FsO2DgHxTr&user_id=DFGRWSAQ&company_id=xyzComp&token_url=https://test.xyz.link.com/successfactors/oauth/token?grant_type=client_credentials&private_key=FG2ASDDFFGJJHHmmdkfWqhdbd5cfsnvVDDGHHHBFGHSF3f6SDFFGHHGjD45dTG4sGHJddf6FG"

Below is the API command I am using to connect to the API

response = requests.get(url=api_url, headers=headers, data=**raw_data**)

Now when I am writing my code like this it is working without any issues. But when I am constructing the raw_data after retrieving the credentials from Secret Manager and saving to different variables and later concatenating to form a string it is not working.

client_id = secret["sf"]["client_id"]
company_id = secret["sf"]["company_id"]
user_id = secret["sf"]["user_id"]
private_key = secret["sf"]["private_key"]


raw_data = "'client_id={}&user_id={}&company_id={}&token_url={}&private_key={}'".format(client_id, user_id, company_id, token_url, private_key)

If I am Printing the raw_data variable after the concatenation it is showing exact same string but this way I am not able to connect.

Hence, I would like to understand if concatenation is using actual meaning of special characters in a string due to which it is causing issue.

I have used other ways of concatenating these variables and all are throwing same error.

Please advise.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *