强制使用请求库的库使用我的代理人在Get Request中明确定义
我正在尝试使用RDFLIB解析RDF文件。但是,在提出请求时,我必须使用代理,但我不知道如何让rdflib使用我的代理。
import rdflib
g = rdflib.Graph()
g.parse(url)
结果:
trackback(最近的最新通话):文件 “ c:\ users \ d72704 \ pycharmprojects \ notology \ main.py”,第113行,in read_rdf()文件“ c:\ users \ ders \ d72704 \ pycharmprojects \ notology \ main.py”,第21行,in read_rdf g.parse(r'https://spec.edmcouncil.org/fibo/ontology/loan/loan/loanseraly/loans/loan') 文件 “ c:\ users \ d72704 \ appdata \ roaming \ python \ python \ python39 \ site-packages \ rdflib \ graph.py”, 第1234行,解析 source = create_input_source(file“ c:\ users \ d72704 \ appdata \ roaming \ roaming \ python \ python \ python39 \ site-packages \ rdflib \ rdflib \ parser.py”, 第326行,在create_input_source中 )= _CREATE_INPUT_SOURCE_FROM_LOCATION(文件“ C:\ Users \ users \ d72704 \ appData \ roaming \ roaming \ python \ python \ python39 \ site-packages \ rdflib \ rdflib \ parser.parser.py”, 第375行,在_create_input_source_from_location input_source = urlinputsource(absolute_location,format)文件“ c:\ users \ users \ d72704 \ appdata \ roaming \ python \ python \ python \ python39 \ site-packages \ rdflib \ rdflib \ parser.py”, 第218行, init file = _urlopen(req)file“ c:\ users \ d72704 \ appdata \ roaming \ roaming \ python \ python \ python39 \ site-packages \ rdflib \ rdflib \ parser.py”, 第206行,在_urlopen中 返回urlopen(req)文件“ c:\ program文件\ python39 \ lib \ urllib \ request.py”,第214行,在urlopen中 返回opener.open(url,data,timeout)文件“ c:\ program files \ python39 \ lib \ urllib \ request.py”,第517行 响应= self._open(req,data)文件“ C:\ Program Files \ Python39 \ lib \ urllib \ unllib \ request.py”,第534行,in _open 结果= self。 _call_chain 结果= func(*args)文件“ c:\ program文件\ python39 \ lib \ urllib \ unepts.py”,第1389行,在https_open中 返回self.do_open(http.client.httpsconnection,req,req,file“ c:\ program files \ python39 \ lib \ urllib \ urellib \ request.py.py”,第1349行,in do_open 提升Urlerror(err)urllib.error.urlerror:< urlopen错误[WinError 10054]现有连接被现有的连接密闭 远程主机>
我可以看到rdflib调用了请求库 “ C:\ Program Files \ Python39 \ Lib \ Urllib \ request.py” 但是我不知道如何通过get请求来传递代理值,而get请求
proxies = {myproxyhere}
r = requests.get(myurlhere, proxies=proxies, timeout=5)
我无法更改我的Windows代理设置,因为管理员约束,如果我尝试设置Pycharm Proxy,则会失败此错误
连接的问题:接收致命警报:stolopt_version
I'm trying to parse an RDF file using RDFLib. However, I have to use a proxy when making requests and I don't know how to get RDFLib to use my proxy.
import rdflib
g = rdflib.Graph()
g.parse(url)
results in:
Traceback (most recent call last): File
"C:\Users\d72704\PycharmProjects\Ontology\main.py", line 113, inRead_RDF() File "C:\Users\d72704\PycharmProjects\Ontology\main.py", line 21, in
Read_RDF
g.parse(r'https://spec.edmcouncil.org/fibo/ontology/LOAN/LoansGeneral/Loans/Loan')
File
"C:\Users\d72704\AppData\Roaming\Python\Python39\site-packages\rdflib\graph.py",
line 1234, in parse
source = create_input_source( File "C:\Users\d72704\AppData\Roaming\Python\Python39\site-packages\rdflib\parser.py",
line 326, in create_input_source
) = _create_input_source_from_location( File "C:\Users\d72704\AppData\Roaming\Python\Python39\site-packages\rdflib\parser.py",
line 375, in _create_input_source_from_location
input_source = URLInputSource(absolute_location, format) File "C:\Users\d72704\AppData\Roaming\Python\Python39\site-packages\rdflib\parser.py",
line 218, in init
file = _urlopen(req) File "C:\Users\d72704\AppData\Roaming\Python\Python39\site-packages\rdflib\parser.py",
line 206, in _urlopen
return urlopen(req) File "C:\Program Files\Python39\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout) File "C:\Program Files\Python39\lib\urllib\request.py", line 517, in open
response = self._open(req, data) File "C:\Program Files\Python39\lib\urllib\request.py", line 534, in _open
result = self._call_chain(self.handle_open, protocol, protocol + File "C:\Program Files\Python39\lib\urllib\request.py", line 494, in
_call_chain
result = func(*args) File "C:\Program Files\Python39\lib\urllib\request.py", line 1389, in https_open
return self.do_open(http.client.HTTPSConnection, req, File "C:\Program Files\Python39\lib\urllib\request.py", line 1349, in
do_open
raise URLError(err) urllib.error.URLError: <urlopen error [WinError 10054] An existing connection was forcibly closed by the
remote host>
I can see that the requests library is being called by RDFLib
"C:\Program Files\Python39\lib\urllib\request.py"
But I don't know how to pass my proxy values as I would do with a get request which does works
proxies = {myproxyhere}
r = requests.get(myurlhere, proxies=proxies, timeout=5)
I cannot alter my windows proxy settings due to admin constrains and if I try to set up the pycharm proxy it fails with this error
Problem with connection: Received fatal alert: protocol_version
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您更仔细地读取回溯,您会发现rdflib不使用请求库,而是
urllib.request
来自标准库中的模块。它的文档告诉它,它使用
http_proxy
和https_proxy
环境变量(如果设置这些设置)定义的代理。因此,您可以将它们设置为:(
请求还依赖于相同的环境变量,因此相同的解决方案将与使用请求的库一起使用。)
If you read the traceback more closely, you'll see that rdflib is not using the Requests library but rather the
urllib.request
module from the standard library.Its documentation tells that it uses proxies defined by the
http_proxy
andhttps_proxy
environment variables if those are set.So you can set them:
(Requests also relies on those same environment variables, so the same solution will work with libraries that do use Requests.)