Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中带有requests.get()的XHR请求的响应不完整_Python_Ajax_Python 3.x_Python Requests_Xmlhttprequest - Fatal编程技术网

python中带有requests.get()的XHR请求的响应不完整

python中带有requests.get()的XHR请求的响应不完整,python,ajax,python-3.x,python-requests,xmlhttprequest,Python,Ajax,Python 3.x,Python Requests,Xmlhttprequest,我试图在服务器上使用Python的请求来获取给定城市中给定街道的德国邮政编码(PLZ)。我正在努力应用我学到的东西 我想退回你的PLZ Schanzäckerstr.在Nürnberg中 import requests url = 'https://www.11880.com/ajax/getsuggestedcities/schanz%C3%A4ckerstra%C3%9Fe%20n%C3%BCrnberg?searchString=schanz%25C3%25A4ckerstra%25C3

我试图在服务器上使用Python的请求来获取给定城市中给定街道的德国邮政编码(PLZ)。我正在努力应用我学到的东西

我想退回你的PLZ
Schanzäckerstr.
Nürnberg

import requests

url = 'https://www.11880.com/ajax/getsuggestedcities/schanz%C3%A4ckerstra%C3%9Fe%20n%C3%BCrnberg?searchString=schanz%25C3%25A4ckerstra%25C3%259Fe%2520n%25C3%25BCrnberg'

data = 'searchString=schanz%25C3%25A4ckerstra%25C3%259Fe%2520n%25C3%25BCrnberg'


headers = {"Authority": "wwww.11880.com",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0",
                "Accept": "application/json, text/javascript, */*; q=0.01",
                "Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
                "Accept-Encoding": "gzip, deflate, br",
                "X-Requested-With": "XMLHttpRequest",
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                "Content-Length": "400",
                "Origin": "https://www.postleitzahlen.de",
                "Sec-Fetch-Site": "cross-site",
                "Fetch-Mode": "cors",
                "DNT": "1",
                "Connection": "keep-alive",
                "Referer": "https://www.postleitzahlen.de",
               }
multipart_data = {(None, data,)}

session = requests.Session()
response = session.get(url, files=multipart_data, headers=headers)

print(response.text)
上面的代码生成类型为200的空响应。我想返回:

'90443'

我能够使用Namingm openstreetmap API解决这个问题。还可以添加街道号码

import requests
city = 'Nürnberg'
street = 'Schanzäckerstr. 2'

response = requests.get( 'https://nominatim.openstreetmap.org/search', headers={'User-Agent': 'PLZ_scrape'}, params={'city': city, 'street': street[1], 'format': 'json', 'addressdetails': '1'}, )
print(street, ',', [i.get('address').get('postcode') for i in response.json()][0])
确保每秒只发送一个请求