Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django Rest框架中测试,是否复制此curl请求?_Python_Django_Curl_Django Rest Framework - Fatal编程技术网

Python 在Django Rest框架中测试,是否复制此curl请求?

Python 在Django Rest框架中测试,是否复制此curl请求?,python,django,curl,django-rest-framework,Python,Django,Curl,Django Rest Framework,我正在尝试为(指向测试的链接)运行一些测试,并重现此curl调用: curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" http://<client_id>:<client_secret>@127.0.0.1:8000/v1/token/ curl-X POST-d“授权类型=密码&用户名=&密码=” http://:@127

我正在尝试为(指向测试的链接)运行一些测试,并重现此curl调用:

curl -X POST -d "grant_type=password&username=<user_name>&password=<password>"
http://<client_id>:<client_secret>@127.0.0.1:8000/v1/token/
curl-X POST-d“授权类型=密码&用户名=&密码=”
http://:@127.0.0.1:8000/v1/token/
这就是我尝试过的:

  def test_oauth2_token_for_user(self):
        """
        Test Django OAuth Toolkit and make a request for am access token.
        """
        self.client.credentials(HTTP_AUTHORIZATION='grant_type ' + "password&username=<user_name>&password=<password")
        response = self.client.post('/api/token/')
def-test\u-oauth2\u-token\u用户(自身):
"""
测试Django OAuth Toolkit并请求am访问令牌。
"""

self.client.credentials(HTTP_AUTHORIZATION='grant'u type'+“password&username=&password=这不是标题。这是非常正常的POST数据,正如所示,您可以将字典作为第二个参数传递到
POST

response = self.client.post('/api/token/',
       {'grant_type': 'password', 'username': username, 'password': password})

这不是标题。这是完全正常的POST数据,如图所示,您可以将字典作为第二个参数传递给
POST

response = self.client.post('/api/token/',
       {'grant_type': 'password', 'username': username, 'password': password})

这不是标题。这是完全正常的POST数据,如图所示,您可以将字典作为第二个参数传递给
POST

response = self.client.post('/api/token/',
       {'grant_type': 'password', 'username': username, 'password': password})

这不是标题。这是完全正常的POST数据,如图所示,您可以将字典作为第二个参数传递给
POST

response = self.client.post('/api/token/',
       {'grant_type': 'password', 'username': username, 'password': password})

我找不到通过django的测试客户端发送post数据和授权数据的方法来发布到这个api

我的解决方案设置为使用LiveServerTestCase()进行测试,并使用请求库进行post:

 class AuthTest(LiveServerTestCase):

    def test_auth(self):
        # ...
        requests.post(
            http://localhost:8082/o/token/,
            dict(username="myuser",
                 password="mypass",
                 grant_type="password"
                 ),
            auth=(MYAPP.client_id, MYAPP.client_secret)
        )

我找不到通过django的测试客户端发送post数据和授权数据的方法来发布到这个api

我的解决方案设置为使用LiveServerTestCase()进行测试,并使用请求库进行post:

 class AuthTest(LiveServerTestCase):

    def test_auth(self):
        # ...
        requests.post(
            http://localhost:8082/o/token/,
            dict(username="myuser",
                 password="mypass",
                 grant_type="password"
                 ),
            auth=(MYAPP.client_id, MYAPP.client_secret)
        )

我找不到通过django的测试客户端发送post数据和授权数据的方法来发布到这个api

我的解决方案设置为使用LiveServerTestCase()进行测试,并使用请求库进行post:

 class AuthTest(LiveServerTestCase):

    def test_auth(self):
        # ...
        requests.post(
            http://localhost:8082/o/token/,
            dict(username="myuser",
                 password="mypass",
                 grant_type="password"
                 ),
            auth=(MYAPP.client_id, MYAPP.client_secret)
        )

我找不到通过django的测试客户端发送post数据和授权数据的方法来发布到这个api

我的解决方案设置为使用LiveServerTestCase()进行测试,并使用请求库进行post:

 class AuthTest(LiveServerTestCase):

    def test_auth(self):
        # ...
        requests.post(
            http://localhost:8082/o/token/,
            dict(username="myuser",
                 password="mypass",
                 grant_type="password"
                 ),
            auth=(MYAPP.client_id, MYAPP.client_secret)
        )