抓取网站出415 ERROR HTTP UNSUPPORTED MEDIA TYPE
为什么我的python运行后会出现415 ERROR HTTP UNSUPPORTED MEDIA TYPE信息,post提取不到数据,求大神帮助[local]1[/local][local]2[/local][local]3[/local]
程序代码:
import re LOGIN_URL = 'https://w3.' #请求的URL地址 DATA = {"TARGET": 'https://w3.', "SMAUTHREASON": '0', "SMENC": 'ISO-8859-1', "SMLOCALE": 'EN-US', "SMAGENTNAME": 't/TX88CtTFIPqQ15ugBfOME66PQGCWGuAAOSByMZUiVIJPozo431pS4LE4YuSGzU', "SMQUERYDATA": '', "POSTPRESERVATIONDATA": '', "USER": 'beijing02', "PASSWORD": 'Jishushi172' } #登录系统的账号密码,也是我们请求数据 HEADERS = { "Accept": 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', "Accept-Encoding": 'gzip, deflate, br', "Accept-Language": 'zh-CN,zh;q=0.9,en;q=0.8', "Cache-Control": 'no-cache', "Connection": 'keep-alive', "Content-Length": '282', "Content-Type": 'application/x-www-form-urlencoded', "Host": 'w3.', "Origin": 'https://w3.', "Pragma": 'no-cache', "Referer": 'https://w3.', "Upgrade-Insecure-Requests": '1', "User-Agent": 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36' } def Get_Session(URL,DATA,HEADERS): '''保存登录参数''' ROOM_SESSION = requests.Session() ROOM_SESSION.post(URL,data=DATA,headers=HEADERS) return ROOM_SESSION SESSION =Get_Session(LOGIN_URL,DATA,HEADERS) # 保存session后再次请求对应的地址 ScrapyDATA = {"msnList": '[]', "pnList": '[]'} #登录系统的账号密码,也是我们请求数据 ScrapyHEADERS = { "Accept": 'application/json, text/plain, */*', "Accept-Encoding": 'gzip, deflate, br', "Accept-Language": 'zh-CN,zh;q=0.9,en;q=0.8', "Access-Control-Allow-Origin": '*', "Cache-Control": 'no-cache', "Connection": 'keep-alive', "Content-Length": '26', "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8', "Host": 'w3.', "Origin": 'https://w3.', "Pragma": 'no-cache', "Referer": 'https://w3.', "User-Agent": 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36' } _cookies = SESSION.cookies scrapyURL="https://w3." d=SESSION.post(scrapyURL,data=ScrapyDATA,headers=ScrapyHEADERS) print (d.text) #d=requests.get("https://w3.,cookies=_cookies) #res_value=d.json() #d1 = json.dumps(res_value,sort_keys=True,ensure_ascii=False,indent=4) #print d1