HTTP request 415 error-unsupported media type (unsupported media type)
There are usually the following situations:
1: Check your HTTP request header information. For example, the User-Agent is set by the server to reject the request;
For example, the crawler you write may be rejected because it is not disguised as a browser.
User-Agent details
2: view your HTTP Request Method and server-side settings
For example, there is an interface that forces post requests. Are you using a non-POST request?
3: POST request parameter settings. required in JSON format
For example, the following two sections of code,
The following JSON parameter, body
import requestsimport jsonpayload={"userName":"names","userCode":"123456","phoneNum":"7800","regPic":"picData"}headers={‘content-type‘: ‘application/json‘}burl="http://httpbin.org/post"r=requests.post(burl, data=json.dumps(payload), headers=headers)print r.text
The following form format parameters
import requestsimport jsonpayload={"userName":"names","userCode":"123456","phoneNum":"7800","regPic":"picData"}headers={‘content-type‘: ‘application/json‘}burl="http://httpbin.org/post"r=requests.post(burl, data=payload, headers=headers)print r.text
HTTP request 415 error-unsupported media type (unsupported media type)