python请求后查询失败:cookies?

2024-09-30 10:33:00 发布

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

我试图执行这个post,但是我得到了server error 500

import requests
base_url = "https://www.assurland.com/ws/CarVehiculeSearch.asmx"
url = "%s/%s"% (base_url,"GetCarBodyTypeListByCarAlim")
pars ={"CarAlim":"DIES","CarType": "A7", "CodeMake": "AUDI", "FirstDrivingDate": "2015-09-22"}

with requests.Session() as s:
    r = s.post(url,data=pars)
    print r.status_code

 ## 500 

我想我需要做些饼干或其他的东西。在

提前谢谢你的帮助。在


Tags: httpsimportcomurlbasewsserverwww
2条回答

该站点上的大多数API访问点似乎已损坏。你的代码本身没有问题。实际上,即使使用常规浏览器,我也无法让网站在自己的web界面中对任何请求做出响应。在

您还可以使用SOAP protocol创建查询的main API documentation详细信息(法语);Python有{a3}可供选择。在

然而,我也没有运气让它发挥作用。使用优秀的^{} library我试图访问更简单的^{} endpoint(注意,我必须使用datetime()对象来建模时间戳):

>>> from zeep import Client
>>> client = Client('https://www.assurland.com/ws/CarVehiculeSearch.asmx?WSDL')
>>> client.service.GetMainCarMakeListByFirstDrivingDate(FirstDrivingDate=datetime(2015, 9, 22))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mjpieters/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/zeep/client.py", line 25, in __call__
    self._op_name, args, kwargs)
  File "/Users/mjpieters/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/zeep/wsdl/bindings/soap.py", line 109, in send
    return self.process_reply(client, operation_obj, response)
  File "/Users/mjpieters/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/zeep/wsdl/bindings/soap.py", line 145, in process_reply
    return self.process_error(doc, operation)
  File "/Users/mjpieters/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/zeep/wsdl/bindings/soap.py", line 223, in process_error
    detail=fault_node.find('detail'))
zeep.exceptions.Fault: <exception str() failed>

一个Fault在这里相当于一个500错误。在

当我enable debug logging时,我们可以看到服务器在生成响应时出现问题:

^{pr2}$

其中隐藏着错误消息:

Le serveur n'a pas pu traiter la demande. -> Erreur lors de la génération du document XML. -> Le type common.FormDataListItem n'était pas attendu. Utilisez l'attribut XmlInclude ou SoapInclude pour spécifier les types qui ne sont pas connus statiquement.

或者,在谷歌翻译的帮助下,用英语:

The server could not process the request. -> Error generating the XML document. -> The type common.FormDataListItem was not expected. Use XmlInclude or SoapInclude attribute to specify types that are not known statically.

由于我们没有发送任何common.FormDataListItem类型、消息抱怨说,不能生成的XML文档,这在我看来像是服务器端编程错误。在

有一些方法可以通过SOAP来工作:

>>> client.service.GetCarTypeListByCodeMake(CodeMake='BMW', FirstDrivingDate=datetime(2016, 1, 1))
['I3', 'I8', 'M2', 'M3', 'M4', 'M5', 'M6', 'SERIE 1 II', 'SERIE 2', 'SERIE 3 VI', 'SERIE 4', 'SERIE 5', 'SERIE 6', 'SERIE 7', 'X1', 'X3', 'X4', 'X5', 'X6', 'Z4']
>>> client.service.GetAllCarTypeListByCodeMake(CodeMake='BMW')
['1502', '1600', '1602', '1800', '1802', '2000', '2002', '2500', '3,0', '3,3', '315', '316', '318', '320', '323', '324', '325', '328', '330', '518', '520', '523', '524', '525', '528', '530', '535', '540', '545', '550', '628', '630', '633', '635', '645', '650', '725', '728', '730', '732', '733', '735', '740', '745', '750', '760', '840', '850', 'I3', 'I8', 'L7', 'M2', 'M3', 'M4', 'M5', 'M535', 'M6', 'M635', 'SERIE 1', 'SERIE 1 II', 'SERIE 2', 'SERIE 3', 'SERIE 3 (SUITE)', 'SERIE 3 VI', 'SERIE 4', 'SERIE 5', 'SERIE 6', 'SERIE 7', 'X1', 'X3', 'X4', 'X5', 'X6', 'Z1', 'Z3', 'Z4', 'Z8']

或通过使用requests发布application/x-www-form-urlencoded数据:

>>> response = requests.post('https://www.assurland.com/ws/CarVehiculeSearch.asmx/GetCarTypeListByCodeMake', data={'CodeMake': 'BMW', 'FirstDrivingDate': datetime(2016, 1, 1)})
>>> print(response.text)
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <anyType xsi:type="xsd:string">I3</anyType>
  <anyType xsi:type="xsd:string">I8</anyType>
  <anyType xsi:type="xsd:string">M2</anyType>
  <anyType xsi:type="xsd:string">M3</anyType>
  <anyType xsi:type="xsd:string">M4</anyType>
  <anyType xsi:type="xsd:string">M5</anyType>
  <anyType xsi:type="xsd:string">M6</anyType>
  <anyType xsi:type="xsd:string">SERIE 1 II</anyType>
  <anyType xsi:type="xsd:string">SERIE 2</anyType>
  <anyType xsi:type="xsd:string">SERIE 3 VI</anyType>
  <anyType xsi:type="xsd:string">SERIE 4</anyType>
  <anyType xsi:type="xsd:string">SERIE 5</anyType>
  <anyType xsi:type="xsd:string">SERIE 6</anyType>
  <anyType xsi:type="xsd:string">SERIE 7</anyType>
  <anyType xsi:type="xsd:string">X1</anyType>
  <anyType xsi:type="xsd:string">X3</anyType>
  <anyType xsi:type="xsd:string">X4</anyType>
  <anyType xsi:type="xsd:string">X5</anyType>
  <anyType xsi:type="xsd:string">X6</anyType>
  <anyType xsi:type="xsd:string">Z4</anyType>
</ArrayOfAnyType>

您可能需要联系这个API的维护人员来解决这个问题,这不是在Python方面可以解决的问题。在

问题是网站处理不当的日期格式。在

错误500包含以下描述:

Erreur lors de la g&#233;n&#233;ration du document XML.  -> Le type common.FormDataListItem n&#39;&#233;tait pas attendu. Utilisez l&#39;attribut XmlInclude ou SoapInclude pour sp&#233;cifier les types qui ne sont pas connus statiquement.

在他们的页面上从您的浏览器中尝试,以获得更友好的调试: https://www.assurland.com/ws/CarVehiculeSearch.asmx?op=GetCarBodyTypeListByCarAlim

注:“attributxmlcludeouSoapIncludepour spécifier les types qui ne sont pas connus车站”

所以我试着用另一种格式输入日期。在

例如:

^{pr2}$

19 Jan 2001

您得到200 OK请求-在本例中是一个空结果。在

enter image description here

不幸的是,过了一年之后,这种格式似乎也不被接受:2001年9月22日的收益率为200英镑,但2015年9月22日的收益率为200英镑 2008年12月31日。在

尝试使用其他日期时间格式。。。但看起来那里有任何东西。。。获取其他站点:)

相关问题 更多 >

    热门问题