【问题标题】:What Im doing wrong in this json request?我在这个 json 请求中做错了什么?
【发布时间】:2018-03-21 19:57:06
【问题描述】:

我正在尝试从https://www.correoargentino.com.ar/formularios/cpa 的表单中获得回复 Wathing请求头我做了以下代码:

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 的响应时,我得到了正确的响应。我与之抗争是因为请求的来源/引用者,但后来我更改了标头并不断收到相同的错误。

欢迎任何帮助

【问题讨论】:

  • 请包含错误的全文(如果是python异常则回溯)。
  • 问题是reCAPTCHA值和请求方法是POST
  • glibdub 没有回溯,服务器应答错误。你可以执行代码来获取请求
  • @kip 在您选择一个州时的表单中,如果您检查网络请求,它会响应城市,而不是点击 reCAPTCHA,我需要用于填充城市选择框的响应跨度>

标签: python json request python-requests urllib


【解决方案1】:

把你使用的方法改成.post,记住这个方法的第二个参数是data

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多