python - 有“urllib.error.URLError:" 尝试自动化脚本时出错,但在 Spyder 中运行正常
问题描述
所以我有一个脚本可以从某些网站上读取表格。
当我在 Python IDE 中运行这个脚本时,它运行良好。如果我尝试将它作为批处理文件独立运行,它就不起作用。它反映了以下错误:urllib.error.URLError:
关于可能导致它的任何想法?我的脚本很短:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 20:24:04 2019
@author: blueb
"""
import requests
import numpy as np
import pandas as pd
dfs = pd.read_html("https://www.nea.gov.sg/dengue-zika/dengue/dengue-clusters")
count = 0
for df in dfs:
count += 1
print(df.head())
clusters_info = dfs[1]
clusters_info.to_csv('clusters.csv')
dls = "https://www.moh.gov.sg/docs/librariesprovider5/diseases-updates/weekly-infectious-bulletin_caseswk32y2019.xlsx?sfvrsn=cceaba67_0"
resp = requests.get(dls)
output = open('denguetrends.xlsx', 'wb')
output.write(resp.content)
output.close()
trends = pd.read_excel('denguetrends.xlsx')
trends.to_csv('denguetrends.csv')
解决方案
http
如果此页面支持,则使用解决方法。真正的问题是环境中的 Python 安装 [broken SSL
]:
urllib HTTPS 请求:<urlopen 错误未知 url 类型:https>
您是否构建了发生这种情况的 Python 环境?还是预先包装好的?
>>> import ssl
ImportError: No module named ssl
Spyder
在任何情况下,您的安装使用的 Python 解释器没有在适当的SSL
支持下编译,或者与您系统的SSL
. 确保在安装SSL
之前安装Spyder
. 以下是一些可以帮助您的资源:
推荐阅读
- jenkins - 未处理的异常:System.ComponentModel.Win32Exception:系统找不到指定的文件
- java - 不支持 1.8 版
- apache-zookeeper - 在对 solr 进行几次成功更新后,抛出 SolrException: java.util.concurrent.TimeoutException: Could not connect to ZooKeeper
- python - python3按字典值的属性对字典列表进行排序
- azure - 如何将 Jira 中的 FixVersion 包含到 vsts 工作项迁移?
- html - 如何使用 inline block 或 flex 将嵌套的 div 排列在一起
- node-red - 将相机图像保存为 Node-Red 中的动态文件名
- java - 生成 SOAP Java 客户端时出现 wsimport 身份验证问题
- json - 读取嵌套 JSON 并插入数据库
- angular - 从 Angular 应用程序访问 Spring 云服务器