what is the type of data ? json or dict

Hey!
I am using this library and when I wanted to use ``` request.post() ``` method I was taking data parameter as a dictionary to it and I got some errors, so I read the documentation of this method that says ``` :param data: (optional) Dictionary, list of tuples, bytes, or file-like
        object to send in the body of the :class:`Request`. ```
I change my dictionary to a json string and it was ok!
why this method doesn't accept a dictionary data type?

Requests does support dicts . My guess is the application your trying to post to requires JSON and you need to specify the correct Content-Type header. 

> Hey!
> I am using this library and when I wanted to use `request.post()` method I was taking data parameter as a dictionary to it and I got some errors, so I read the documentation of this method that says `` :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. ``
> I change my dictionary to a json string and it was ok!
> why this method doesn't accept a dictionary data type?

It does, but giving `data` a dict [is for form-encoded data](https://requests.readthedocs.io/en/master/user/quickstart/#more-complicated-post-requests). This should probably be clarified in the API doc though.

As you can see from the third paragraph of the link above, if you want to send JSON data as the request entity-body, you can either encoded it manually or use the `json` keyword argument, which  basically does that for you, and furthermore automatically sets the request's content-type to `application/json` (if it's not set explicitly):

> There are times that you may want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly.
> 
> For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data:
> 
> ```
> >>> import json
> 
> >>> url = 'https://api.github.com/some/endpoint'
> >>> payload = {'some': 'data'}
> 
> >>> r = requests.post(url, data=json.dumps(payload))
> ```
> Instead of encoding the dict yourself, you can also pass it directly using the json parameter (added in version 2.4.2) and it will be encoded automatically:
> ```
> >>> url = 'https://api.github.com/some/endpoint'
> >>> payload = {'some': 'data'}
> 
> >>> r = requests.post(url, json=payload)
> ```
> Note, the json parameter is ignored if either data or files is passed.
> 
> Using the json parameter in the request will change the Content-Type in the header to application/json.

It's hard to know for sure as you're not providing the relevant information, but I'm guessing the errors were because the application you were posting to tried to decode the form-encoded entity-body as json and that obviously failed.

@xmo-odoo is correct, if you’re attempting to send JSON data, you’ll need to either manually encode it or use the json parameter. The semantics of a dictionary being passed to `data` are that it will be form-encoded.

> > Hey!
> > I am using this library and when I wanted to use `request.post()` method I was taking data parameter as a dictionary to it and I got some errors, so I read the documentation of this method that says `` :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. ``
> > I change my dictionary to a json string and it was ok!
> > why this method doesn't accept a dictionary data type?
> 
> It does, but giving `data` a dict [is for form-encoded data](https://requests.readthedocs.io/en/master/user/quickstart/#more-complicated-post-requests). This should probably be clarified in the API doc though.
> 
> As you can see from the third paragraph of the link above, if you want to send JSON data as the request entity-body, you can either encoded it manually or use the `json` keyword argument, which basically does that for you, and furthermore automatically sets the request's content-type to `application/json` (if it's not set explicitly):
> 
> > There are times that you may want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly.
> > For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data:
> > ```
> > >>> import json
> > 
> > >>> url = 'https://api.github.com/some/endpoint'
> > >>> payload = {'some': 'data'}
> > 
> > >>> r = requests.post(url, data=json.dumps(payload))
> > ```
> > 
> > 
> > Instead of encoding the dict yourself, you can also pass it directly using the json parameter (added in version 2.4.2) and it will be encoded automatically:
> > ```
> > >>> url = 'https://api.github.com/some/endpoint'
> > >>> payload = {'some': 'data'}
> > 
> > >>> r = requests.post(url, json=payload)
> > ```
> > 
> > 
> > Note, the json parameter is ignored if either data or files is passed.
> > Using the json parameter in the request will change the Content-Type in the header to application/json.
> 
> It's hard to know for sure as you're not providing the relevant information, but I'm guessing the errors were because the application you were posting to tried to decode the form-encoded entity-body as json and that obviously failed.

I'm sorry for delaying,
yes, I realized what you said, and In my idea, the documentation should be clarified.
Thanks

I second what @mmdaz says about the documentation needing to be clarified. I just spent a lot of time trying to figure out why I could successfully pass a dict to the `json` parameter, but not to the `data` parameter, and a `json-formatted` structure to the `data` parameter, but not to `json`. Nowhere in the docstring is form-encoded data mentioned.

<img width="657" alt="Screen Shot 2020-11-13 at 22 34 07" src="https://user-images.githubusercontent.com/12277715/99189685-469a7680-275a-11eb-83bd-a6dd33cbcc46.png">