首页 > 解决方案 > 使用带有 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)

我一直超时,因为我的代理不起作用,不确定我做错了什么。

标签: python-3.xproxyurllib

解决方案


推荐阅读