r=request.put(url,json={...}), put doesn't accept json as argument while post does? 

http://stackoverflow.com/questions/9733638/post-json-using-python-requests

shows 
r = requests.post('http://httpbin.org/post', json={"key": "value"})

but trying the same thing with put did not seem to work.
had to 
    #r = session.put(url, json=schema) (should work!)
  headers = {'Content-type': 'application/json'}
   r = session.put(url,data=json.dumps(jsonschema),headers=headers)

Hey @githubnovice, I'm unfortunately unable to reproduce this issue with the current information. Could you please provide the version of Requests you're using, the exact request (with parameters), and possibly the traceback you're seeing?

These are the examples I tried.

``` python
>>> import requests
>>> resp = requests.put('http://httpbin.org/put', json={"key": "value"})
>>> resp.json()
{u'url': u'http://httpbin.org/put', ... u'headers': {u'Content-Length': u'16', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.12.0', u'Host': u'httpbin.org', u'Content-Type': u'application/json'}, u'json': {u'key': u'value'}, u'data': u'{"key": "value"}'}

>>> resp = requests.Session().put('http://httpbin.org/put', json={"key": "value"})
>>> resp.json()
{u'url': u'http://httpbin.org/put', ... u'headers': {u'Content-Length': u'16', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.12.0', u'Host': u'httpbin.org', u'Content-Type': u'application/json'}, u'json': {u'key': u'value'}, u'data': u'{"key": "value"}'}
```


## Hi Nate: thanks for the fast response!

TypeError                                 Traceback (most recent call last)
/home/gladwig/GNS3/Python/mkint.py in <module>()
    105
    106 if **name** == "**main**":
--> 107     main()

/home/gladwig/GNS3/Python/mkint.py in main()
     94     #print json.dumps(sla, indent=4, separators=(',', ': '))
     95     #return
---> 96     put_l2interface_state(s,controller_url,"gigabitethernet1",False)
     97     l2 = get_l2interface_state(s,controller_url,"gigabitethernet1")
     98     print "g1 = "

/home/gladwig/GNS3/Python/mkint.py in put_l2interface_state(session, c_url, interface, enable)
     61     url = c_url + 'api/v1/interfaces/' + interface +'/state'
     62     pdb.set_trace()
---> 63     resp = session.put(url, json=schema) #(should work!)
     64     #headers = {'Content-type': 'application/json'}
     65     #resp = session.put(url,data=json.dumps(schema),headers=headers)

/usr/lib/python2.7/dist-packages/requests/sessions.pyc in put(self, url, data, *_kwargs)
    505         """
    506
--> 507         return self.request('PUT', url, data=data, *_kwargs)
    508
    509     def patch(self, url, data=None, **kwargs):

TypeError: request() got an unexpected keyword argument 'json'

The version is: gladwig@ovs-linux-3:~/GNS3/Python$ pip show requests
Name: requests
Version: 2.12.1
Summary: Python HTTP for Humans.
The variables before the call are:
-> resp = session.put(url, json=schema) #(should work!)
(Pdb) print url
https://192.168.1.181:55443/api/v1/interfaces/gigabitethernet1/state
(Pdb) print schema
{'if-name': 'gigabitethernet1', 'enabled': False}
(Pdb)

From: Nate Prewitt [mailto:notifications@github.com]
Sent: Thursday, November 17, 2016 7:56 PM
To: kennethreitz/requests requests@noreply.github.com
Cc: Geoff Ladwig gladwig@gladworx.com; Mention mention@noreply.github.com
Subject: Re: [kennethreitz/requests] r=request.put(url,json={...}), put doesn't accept json as argument while post does? (#3707)

Hey @githubnovicehttps://github.com/githubnovice, I'm unfortunately unable to reproduce this issue with the current information. Could you please provide the version of Requests you're using, the exact request (with parameters), and possibly the traceback you're seeing?

These are the examples I tried.

> > > import requests
> > > 
> > > resp = requests.put('http://httpbin.org/put', json={"key": "value"})
> > > 
> > > resp.json()

{u'url': u'http://httpbin.org/put', ... u'headers': {u'Content-Length': u'16', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'_/_', u'User-Agent': u'python-requests/2.12.0', u'Host': u'httpbin.org', u'Content-Type': u'application/json'}, u'json': {u'key': u'value'}, u'data': u'{"key": "value"}'}

> > > resp = requests.Session().put('http://httpbin.org/put', json={"key": "value"})
> > > 
> > > resp.json()

{u'url': u'http://httpbin.org/put', ... u'headers': {u'Content-Length': u'16', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'_/_', u'User-Agent': u'python-requests/2.12.0', u'Host': u'httpbin.org', u'Content-Type': u'application/json'}, u'json': {u'key': u'value'}, u'data': u'{"key": "value"}'}

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/kennethreitz/requests/issues/3707#issuecomment-261417796, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIiYHe1b5pcybkaEAEMr_azFPMAh8xm2ks5q_PeHgaJpZM4K19xY.


Hmm, so I'm still unable to reproduce this. I think I've got an idea of what the issue you're hitting now is though.

If you'll note the traceback you provided, the call to `return self.request('PUT', url, data=data, **kwargs)` in sessions.py occurs on line 507. The last time this line existed in that region of the code was in Requests 2.4.0 which was prior to the existence of the `json` param. You almost certainly have multiple copies of requests on your system and the older one is taking precedence here.

I would encourage running your code into a [virtualenv](https://virtualenv.pypa.io/en/stable/), if you're not already using one. You may also consider taking a look at what's installed in /usr/lib/python2.7/dist-packages/requests. My guess is it will be Requests 2.4, or at least .pyc files containing that code. I'm afraid that's all the help I can provide without a simpler and complete reproduction example.


You are probably right. I just recently load virtualenv (pyenv?) and am not expert at using it..
I should have suspected it, but I just pip’d request and haven’t changed versions.. I’ll look further..
Geoff

From: Nate Prewitt [mailto:notifications@github.com]
Sent: Thursday, November 17, 2016 8:43 PM
To: kennethreitz/requests requests@noreply.github.com
Cc: Geoff Ladwig gladwig@gladworx.com; Mention mention@noreply.github.com
Subject: Re: [kennethreitz/requests] r=request.put(url,json={...}), put doesn't accept json as argument while post does? (#3707)

Hmm, so I'm still unable to reproduce this. I think I've got an idea of what the issue you're hitting now is though.

If you'll note the traceback you provided, the call to return self.request('PUT', url, data=data, **kwargs) in sessions.py occurs on line 507. The last time this line existed in that region of the code was in Requests 2.4.0 which was prior to the existence of the json param. You almost certainly have multiple copies of requests on your system and the older one is taking precedence here.

I would encourage running your code into a virtualenvhttps://virtualenv.pypa.io/en/stable/, if you're not already using one. You may also consider taking a look at what's installed in /usr/lib/python2.7/dist-packages/requests. My guess is it will be Requests 2.4, or at least .pyc files containing that code. I'm afraid that's all the help I can provide without a simpler and complete reproduction example.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/kennethreitz/requests/issues/3707#issuecomment-261425415, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIiYHUdEmluX7Y-Dwq3TV9wjm1m5xU8Qks5q_QKZgaJpZM4K19xY.


Ok. You are right.
This was a problem in my lib path.
Thanks,
Geoff

From: Nate Prewitt [mailto:notifications@github.com]
Sent: Thursday, November 17, 2016 8:43 PM
To: kennethreitz/requests requests@noreply.github.com
Cc: Geoff Ladwig gladwig@gladworx.com; Mention mention@noreply.github.com
Subject: Re: [kennethreitz/requests] r=request.put(url,json={...}), put doesn't accept json as argument while post does? (#3707)

Hmm, so I'm still unable to reproduce this. I think I've got an idea of what the issue you're hitting now is though.

If you'll note the traceback you provided, the call to return self.request('PUT', url, data=data, **kwargs) in sessions.py occurs on line 507. The last time this line existed in that region of the code was in Requests 2.4.0 which was prior to the existence of the json param. You almost certainly have multiple copies of requests on your system and the older one is taking precedence here.

I would encourage running your code into a virtualenvhttps://virtualenv.pypa.io/en/stable/, if you're not already using one. You may also consider taking a look at what's installed in /usr/lib/python2.7/dist-packages/requests. My guess is it will be Requests 2.4, or at least .pyc files containing that code. I'm afraid that's all the help I can provide without a simpler and complete reproduction example.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/kennethreitz/requests/issues/3707#issuecomment-261425415, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIiYHUdEmluX7Y-Dwq3TV9wjm1m5xU8Qks5q_QKZgaJpZM4K19xY.