urllib.error.URLError:< urlopen错误未知的url类型:https> [英] urllib.error.URLError: <urlopen error unknown url type: https>

查看:1187
本文介绍了urllib.error.URLError:< urlopen错误未知的url类型:https>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试学习网络抓取.我在Windows 10中安装了Anaconda3.Conda版本4.5.12. Python版本3.7.1.

Hello I am trying to learn web scraping. I installed Anaconda3 in Windows 10. Conda version 4.5.12. Python version 3.7.1.

我写了下面的脚本,该脚本会产生上述错误.

I wrote following script which produces the mentioned error.

import bs4
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as request
with request('https://google.com') as response:
    page_html = response.read()
page_soup = soup(page_html, "html.parser")
print(page_soup)

该错误来自此行:

with request('https://google.com') as response:
...
...
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: https>

但是,当我打开Anaconda提示符并从上面的脚本逐行执行时,它运行正常.
谁能帮助我了解问题出在哪里?如何在不出现此错误的情况下从控制台运行脚本?

However, when I opened up my Anaconda prompt and executed line by line from above script it worked flawlessly.
Can Anyone help me understand what went wrong? How can I make the script run from the console without getting this error?

推荐答案

我通过重新安装anaconda库解决了该问题.在安装过程中,我选择设置PATH变量,尽管不建议这样做. (因此我没有第一次设置PATH)因此,基本上我忽略了建议.在那之后它起作用了.我不知道是什么原因造成了第一次.但是现在可以了.

I solved the problem by reinstalling the anaconda library. On the installation process I chose to set up the PATH variable although it was not recommended. ( So i did not set the PATH first time ) So, basically I ignored the recommendation. And After that it worked. I do not know exactly what caused the problem first time. But now it is working.

这篇关于urllib.error.URLError:&lt; urlopen错误未知的url类型:https&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆