Skip to content

Invalid username/password when working with RequestsClient or CoreapiClient #4642

@brainyl

Description

@brainyl

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"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions