python-3.x - 使用带有 urllib 的代理时遇到问题
问题描述
我正在尝试使用代理,以便我可以访问外部数据。我的代理似乎没有工作。我正在使用 Python 3 和 urllib。
我尝试将代理 = 代理提供给 urlopen。我尝试过使用 ProxyHandler。
#Importing dataframe and request stuff
import pandas as pd
import json
import urllib
from urllib.request import urlopen
from urllib.request import ProxyHandler
#mapping proxy dictionary
proxies = {
'ftp': 'ftp://x:80',
'http': 'http://x:80',
'https': 'https://x:80'
}
#handling the proxy
proxy_support = urllib.request.ProxyHandler(proxies)
下面的代码可能无关紧要,但我不知道。
#Identifying the file
json_file = "https://gis.fema.gov/arcgis/rest/services/NSS/OpenShelters/MapServer/0/query?where=1%3D1&outFields=*&returnGeometry=false&outSR=4326&f=json"
#reading the file
data = urlopen(json_file).read()
#loading data
raw_json = json.loads(data)
#formatting data
formatted_json = [feature['attributes'] for feature in raw_json['features']]
#creating data frame
df = pd.DataFrame(formatted_json)
我一直超时,因为我的代理不起作用,不确定我做错了什么。
解决方案
推荐阅读
- php - Symfony:如何获取与 oneToMany 关系相关的所有用户帖子
- javascript - javascript 代码错误:未捕获的 ReferenceError:**** 未在 HTMLDivElement.onclick 中定义
- angular - 如何在 Angular 中通过 Angular Material 使用浏览器的表单数据值
- android - 在反应本机后台下载器中更改并发限制
- i2c - Rs485和I2C显示器一起使用
- python - Pandas - 根据 value_counts() 结果重新编码变量
- javascript - 为什么我得到一个带有 Promisify 的 TypeError
- javascript - 如何在用javascript返回结果之前完成.map?
- angular - Angular 中的类型化管道
- c# - 如何在 Rx.Net 中使用异步累加器实现 ScanAsync 运算符?