-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Invalid username/password when working with RequestsClient or CoreapiClient #4642
Copy link
Copy link
Closed
Labels
Description
I have made several attempts to authenticate with my API using RequestsClient or CoreapiClient and both have failed.
Steps to reproduce
Create a simple test
from rest_framework.test import CoreAPIClient, RequestsClient
from unittest import TestCase
from django.conf import settings
from requests.auth import HTTPBasicAuth
from requests import Session
class SampleTest(TestCase):
def test_sample(self):
url = '{0}/app/api/save-data/'.format(settings.BASE_URL)
client = RequestsClient()
client.auth = HTTPBasicAuth('xxxxxxx', 'xxxx123!')
result = client.post(url)
print(result.text, client)
Expected behavior
I expect the request to succeed but the reverse is the case. Although, when I change to request.Session, the code works:
url = '{0}/app/api/save-data/'.format(settings.BASE_URL)
client = Session()
client.auth = HTTPBasicAuth('xxxxxxx', 'xxxx123!')
result = client.post(url)
print(result.text, client)
Actual behavior
After supplying a valid username and password, It says " Invalid username/password"
Reactions are currently unavailable