2016-11-04 33 views
8

Próbuję wykonać ten post ale mam server error 500:Żądanie zapytania po zapytaniu kończy się niepowodzeniem: pliki cookie?

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 

myślę, że trzeba ustawić ciasteczka lub coś innego.

Z góry dziękujemy za pomoc.

+0

spróbuj użyć obiektu sesji. http://docs.python-requests.org/en/master/user/advanced/ – Ajurna

+0

Dlaczego uważasz, że potrzebujesz ustawianie ciasteczek? Serwer HTTP jest czarną skrzynką i może odpowiadać na dowolne żądanie, niezależnie od tego, do jakiego stopnia piekło im odpowiada. Musisz poeksperymentować, jaka kombinacja nagłówków i danych o ciele będzie akceptowana, a co nie. Wiele serwerów jest skonfigurowanych tak, aby akceptowały tylko żądania z niektórych nagłówków 'User-Agent', na przykład (biała lista klientów). Musisz porównać swoje żądania 'request' z żądaniami innych klientów, które działają, i wypróbować jakie różnice między tymi dwoma kwestiami. –

+0

Obecnie nie mogę nawet uruchomić witryny w mojej * przeglądarce *. Wygląda mi na to, że strona jest * zepsuta *, a zatem nie będzie żadnego sposobu na uzyskanie wyniku z tej strony za pomocą 'request'. –

Odpowiedz

5

Większość punktów dostępu do API w tej witrynie wygląda na uszkodzoną. Nie ma nic złego w twoim kodzie per se. Nie mogę uzyskać witryny, aby odpowiedzieć na wszelkie żądania w ich własnym interfejsie WWW, nawet przy użyciu zwykłej przeglądarki.

Szczegóły (w języku francuskim), które można również używać do tworzenia zapytań za pomocą SOAP protocol; Python ma several SOAP client libraries do wyboru.

Jednak nie miałem szczęścia w uzyskaniu tego do pracy albo. Korzystanie z doskonałej zeep library Próbowałem otworzyć prostsze GetMainCarMakeListByFirstDrivingDate endpoint (zauważ, że musiałem użyć datetime() obiekt do modelowania timestamp):

>>> 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 jest odpowiednikiem SOAP od 500 błędu tutaj.

Kiedy enable debug logging, widzimy, że serwer ma problemy z produkcją odpowiedź:

>>> client.service.GetMainCarMakeListByFirstDrivingDate(FirstDrivingDate=datetime(2015, 9, 22)) 
zeep.transports: HTTP Post to https://www.assurland.com/ws/CarVehiculeSearch.asmx: 
<?xml version='1.0' encoding='utf-8'?> 
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap-env:Body> 
    <ns0:GetMainCarMakeListByFirstDrivingDate xmlns:ns0="http://tempuri.org/"> 
     <ns0:FirstDrivingDate>2015-09-22T00:00:00</ns0:FirstDrivingDate> 
    </ns0:GetMainCarMakeListByFirstDrivingDate> 
    </soap-env:Body> 
</soap-env:Envelope> 

zeep.transports: HTTP Response from https://www.assurland.com/ws/CarVehiculeSearch.asmx (status: 500): 
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Le serveur n'a pas pu traiter la demande. ---&gt; Erreur lors de la génération du document XML. ---&gt; 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.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope> 
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> 

Ukryte tam jest komunikat o błędzie:

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

lub z pewnym Google Translate pomocy, w języku angielskim:

Serwer nie może przetworzyć żądania. ---> Błąd generowania dokumentu XML. ---> Typ common.FormDataListItem nie był oczekiwany. Użyj atrybutu XmlInclude lub SoapInclude, aby określić typy, które nie są znane statycznie.

Ponieważ nie wysyła żadnych common.FormDataListItem typy, i komunikat skarży się, że żaden dokument XML może być generowane, to wygląda na błąd programowania po stronie serwera do mnie.

Istnieją metody, które działają albo poprzez 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'] 

lub poprzez opublikowania application/x-www-form-urlencoded dane z requests:

>>> 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> 

Prawdopodobnie będziesz musiał skontaktować się z opiekunami tego API pozbywaj się tego, nie jest to coś, co można uzyskać po stronie Pythona.

+0

Dziękuję za tę szczegółową odpowiedź. Nie wiem, czy to może pomóc, ale przetestować zapytanie "GetCarTypeListByCodeMake" z przeglądarki: https: //www.assurland.com/ws/CarVehiculeSearch.asmx? Op = GetCarTypeListByCodeMake' z 'CodeMake = BMW' i' FirstDrivingDate = 2016 -01-01' działa dobrze dla mnie. – agstudy

+0

@agstudy: rzeczywiście ta funkcja * działa *. Więcej dowodów na to, że strona jest po prostu zepsuta. –

+0

@agstudy: interesujące; Po wprowadzeniu nieprawidłowych informacji w metodzie ['GetCarAlimListByCarType'] (https://www.assurland.com/ws/CarVehiculeSearch.asmx?op=GetCarAlimListByCarType) otrzymasz pustą odpowiedź, ale prawidłowe informacje zawierają błąd. Jest to w 100% błąd na tej stronie. –

1

Problem jest format daty, która jest źle traktowane w miejscu.

Błąd 500 niesie ten opis:

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. 

Wypróbuj go z przeglądarki na ich stronie na bardziej przyjazne dla użytkownika debug: https://www.assurland.com/ws/CarVehiculeSearch.asmx?op=GetCarBodyTypeListByCarAlim

Uwaga: „Attribut XmlInclude ou SoapInclude wlać sp é cifier les rodzaje qui ne sont pas connus statiquement”

Więc spróbowałem trochę przeszukania, aby wprowadzić datę w innym formacie.

Jako przykład:

Fri, 19 Jan 2001 

lub 19 Jan 2001

Otrzymasz 200 OK życzenie - W tym przypadku pusty wynik.

enter image description here

Niestety po pewnym roku, wygląda, że ​​format jest również nie są akceptowane: 22 września 2001 daje 200 OK, ale 22 wrz 2015 nie więcej - to idzie aż 2008-12-31.

Spróbuj z innym formatem datetime ... Ale wygląda na to, że jest tam coś ... Weź inną witrynę :)

Powiązane problemy