当我想利用tbd.getbusdata获取公交站点数据时报错连接超时,用的是jupyter notebook,以前没有这样的情况,麻烦学长康康为什莫。
我的代码如下:
import geopandas as gpd
import transbigdata as tbd
line,stop = tbd.getbusdata("南京", ['1路' , '2路', '3路'], accurate=True, timeout=20)
gdf = gpd.GeoDataFrame(stop)
output_file = 'TBD南京公交数据.csv'
gdf.to_csv(output_file, index=False, encoding = 'utf-8-sig')
jupyter报错如下:
RemoteDisconnected Traceback (most recent call last)
D:\ANACONDA3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
702 # Make the request on the httplib connection object.
--> 703 httplib_response = self._make_request(
704 conn,
D:\ANACONDA3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
448 # Otherwise it looks like a bug in the code.
--> 449 six.raise_from(e, None)
450 except (SocketTimeout, BaseSSLError, SocketError) as e:
D:\ANACONDA3\lib\site-packages\urllib3\packages\six.py in raise_from(value, from_value)
D:\ANACONDA3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
443 try:
--> 444 httplib_response = conn.getresponse()
445 except BaseException as e:
D:\ANACONDA3\lib\http\client.py in getresponse(self)
1376 try:
-> 1377 response.begin()
1378 except ConnectionError:
D:\ANACONDA3\lib\http\client.py in begin(self)
319 while True:
--> 320 version, status, reason = self._read_status()
321 if status != CONTINUE:
D:\ANACONDA3\lib\http\client.py in _read_status(self)
288 # sending a valid response.
--> 289 raise RemoteDisconnected("Remote end closed connection without"
290 " response")
RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
ProtocolError Traceback (most recent call last)
D:\ANACONDA3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
488 if not chunked:
--> 489 resp = conn.urlopen(
490 method=request.method,
D:\ANACONDA3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
786
--> 787 retries = retries.increment(
788 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
D:\ANACONDA3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
549 if read is False or not self._is_method_retryable(method):
--> 550 raise six.reraise(type(error), error, _stacktrace)
551 elif read is not None:
D:\ANACONDA3\lib\site-packages\urllib3\packages\six.py in reraise(tp, value, tb)
768 if value.traceback is not tb:
--> 769 raise value.with_traceback(tb)
770 raise value
D:\ANACONDA3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
702 # Make the request on the httplib connection object.
--> 703 httplib_response = self._make_request(
704 conn,
D:\ANACONDA3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
448 # Otherwise it looks like a bug in the code.
--> 449 six.raise_from(e, None)
450 except (SocketTimeout, BaseSSLError, SocketError) as e:
D:\ANACONDA3\lib\site-packages\urllib3\packages\six.py in raise_from(value, from_value)
D:\ANACONDA3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
443 try:
--> 444 httplib_response = conn.getresponse()
445 except BaseException as e:
D:\ANACONDA3\lib\http\client.py in getresponse(self)
1376 try:
-> 1377 response.begin()
1378 except ConnectionError:
D:\ANACONDA3\lib\http\client.py in begin(self)
319 while True:
--> 320 version, status, reason = self._read_status()
321 if status != CONTINUE:
D:\ANACONDA3\lib\http\client.py in _read_status(self)
288 # sending a valid response.
--> 289 raise RemoteDisconnected("Remote end closed connection without"
290 " response")
ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
C:\Windows\Temp\ipykernel_10028\269894834.py in
1 import geopandas as gpd
2 import transbigdata as tbd
----> 3 line,stop = tbd.getbusdata("上海",['轨道交通1号线'],accurate = True,timeout = 20)
4 gdf = gpd.GeoDataFrame(stop)
5 output_file = r"C:\Users\pythonScript\工具包\工具包\各个城市基础数据(坐标系未知)\TBD上海站点.csv"
D:\ANACONDA3\lib\site-packages\transbigdata\crawler.py in getbusdata(city, keywords, accurate, timeout)
249 for keyword in keywords:
250 print(keyword)
--> 251 for uid in getlineuid(keyword, c, accurate):
252 if uid not in uids:
253 try:
D:\ANACONDA3\lib\site-packages\transbigdata\crawler.py in getlineuid(keyword, c, acc)
182 url = 'http://map.baidu.com/?qt=s&wd=' +
183 urllib.parse.quote(keyword)+'&c='+c+'&from=webmap'
--> 184 response = requests.get(url)
185 searchinfo = json.loads(response.text)
186 try:
D:\ANACONDA3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
71 """
72
---> 73 return request("get", url, params=params, **kwargs)
74
75
D:\ANACONDA3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
57 # cases, and look like a memory leak in others.
58 with sessions.Session() as session:
---> 59 return session.request(method=method, url=url, **kwargs)
60
61
D:\ANACONDA3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
585 }
586 send_kwargs.update(settings)
--> 587 resp = self.send(prep, **send_kwargs)
588
589 return resp
D:\ANACONDA3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
699
700 # Send the request
--> 701 r = adapter.send(request, **kwargs)
702
703 # Total elapsed time of the request (approximately)
D:\ANACONDA3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
545
546 except (ProtocolError, OSError) as err:
--> 547 raise ConnectionError(err, request=request)
548
549 except MaxRetryError as e:
ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))