python - Base64 encode HTTP_AUTHORIZATION headers DRF -


i'm trying create test using django rest framework:

self.api = apiclient() self.api.credentials(http_authorization='client_id ' + str(self.client_id) + ' client_secret ' + str(self.client_secret)) response = self.api.post(url, payload) 

but error above:

invalid basic header. credentials not correctly base64 encoded.

do need base64 encode header? assumed done you? testing same thing curl works no issues i.e.

curl -x post -d "stuff=stuff" http://rqepzpawyyvqal9d:18288ghfrb@127.0.0.1:8000/api/test/ 

you do, in fact, need base64 encode auth strings yourself. in case, believe should like:

import base64  auth = 'client_id %s client_secret %s' % (base64.b64encode(self.client_id),                                           base64.b64encode(self.client_secret)) self.api.credentials(http_authorization=auth) 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -