0

I am trying to make a request following the IBM Tone Analyzer API instructions, and according to the docs this is what it'll look like.

curl -X POST -u "apikey:{apikey}" --header "Content-Type: application/json" --data-binary @tone.json "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2017-09-21"

I converted that to a python request() and I have this:

response = requests.post(url=analyzer_url, header=header, data=data)

the problem is that I have no clue what -u "apikey:{apikey}"'s equivalent is on the request() parameters.

Could anyone help me?

7
  • first result of the search for "python requests authentication". Commented Feb 16, 2019 at 17:23
  • Possible duplicate of how to use python to execute a curl command Commented Feb 16, 2019 at 17:23
  • 1
    Maybe a duplicate but What is the cleanest way to do HTTP POST with basic auth in Python shows you how to add the apikey:{apikey} to your request (which is the username/password for the request). Commented Feb 16, 2019 at 17:26
  • @Bakuriu Your comment helped the most. Thanks. But I didn't know to look for authentication, I didn't even know it was called that. Commented Feb 17, 2019 at 0:29
  • @JimTodd Please read the context of my question... it is not a duplicate. Commented Feb 17, 2019 at 0:31

1 Answer 1

2

Well I did look at this question but I don't think they talk about the -u "apikey:{apikey}" which was the main source of my issue. (what I now know is Authentication).

I found my answer thanks to Bakuriu's reply (here) My final post request looked like this:

res = requests.post(
url, 
headers=headers, 
data=json.dumps(my_json).encode('utf-8'),

auth=("apikey", API_KEY)
)

(I wish the folks in the comment section had taken the time to read the context of my question rather than looking for a duplicate. @ Bakuriu your response helped me the most, but you just didn't submit an actual answer, so I had to answer my own question.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.