在这个json请求中我做错了什么?

2024-06-16 13:31:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从https://www.correoargentino.com.ar/formularios/cpa中的表单得到响应 在请求头中,我编写了以下代码:

import json, requests


import requests
import logging

try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client

http_client.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True


url = "https://www.correoargentino.com.ar/sites/all/modules/custom/ca_forms/api/wsFacade.php/"
code = 'H'
params = dict(
    action="localidades",
    localidad="none",
    calle="",
    altura="",
    provincia=code,
)

resp = requests.get(url=url, params=params,headers={
        'Referer': 'https://www.correoargentino.com.ar/formularios/cpa', 
        'Origin': 'https://www.correoargentino.com.ar',
        'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'X-Requested-With':'XMLHttpRequest',    
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'es-419,es;q=0.9,en-US;q=0.8,en;q=0.7',
        'Cookie': '_ga=GA1.3.2079472460.1521655930; _gid=GA1.3.2041549384.1521655930; has_js=1',
})
print resp.text

但是我发现了一个错误,当我看到Chrome的响应时,我得到了正确的响应。我与之抗争是因为请求的来源/引用者,但后来我更改了头并不断得到相同的错误。你知道吗

欢迎任何帮助


Tags: httpsimportcomclientloghttpurllogging
1条回答
网友
1楼 · 发布于 2024-06-16 13:31:05

将使用的方法更改为.post,请记住此方法中的第二个参数是data

resp = requests.post(url=url, data=params)

相关问题 更多 >