Try using a POST request with the following header: X-HTTP-Method-Override: PATCH This is unique to the Oracle Service Cloud REST API implementation and is documented.
Answer from AlmightyWhy on Stack OverflowTry using a POST request with the following header: X-HTTP-Method-Override: PATCH This is unique to the Oracle Service Cloud REST API implementation and is documented.
In cases where the browser or client application does not support PATCH requests, or network intermediaries block PATCH requests, HTTP tunneling can be used with a POST request by supplying an X-HTTP-Method-Override header.
Example:
import requests
restURL = <Your REST URL>
params = {'field': 'val'}
headers = {'X-HTTP-Method-Override':'PATCH'}
try:
resp = requests.post(restURL, json=params, auth=('<uname>', '<pwd>'), headers=headers)
print resp
except requests.exceptions.RequestException as err:
errMsg = "Error: %s" % err
print errMsg
Can't update API using requests.patch
PATCH update request from python requests library won't work
http - How do I make a PATCH request in Python? - Stack Overflow
Issues with patch request in Python - Stack Overflow
Videos
With Requests, making PATCH requests is very simple:
import requests
r = requests.patch('http://httpbin.org/patch')
Seems to work in 2.7.1 as well.
>>> import urllib2
>>> request = urllib2.Request('http://google.com')
>>> request.get_method = lambda: 'PATCH'
>>> resp = urllib2.urlopen(request)
Traceback (most recent call last):
...
urllib2.HTTPError: HTTP Error 405: Method Not Allowed
Just ran into this same issue. Was missing the trailing slash on the URL. When Django redirected to the URL with the trailing slash, it seemed to drop the payload of the PATCH.
You should check your network traffic to make sure where the problem appears. If I use
import requests
app_user_id = 7
auth = ('someusrname', 'somepwd')
data = {'appUserId': app_user_id}
url = 'http://localhost:8000/someaccounts/1'
r = requests.put(url, data=data, auth=auth)
print r.status_code
and open a local socket with netcat (nc -l 8000) I am getting the data form encoded:
PUT /someaccounts/1 HTTP/1.1
Host: localhost:8000
Content-Length: 11
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.8.1
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Authorization: Basic c29tZXVzcm5hbWU6c29tZXB3ZA==
appUserId=7