Python 尝试自动执行脚本时出现“urllib.error.urleror:”错误,但在Spyder内部运行时效果良好

Python 尝试自动执行脚本时出现“urllib.error.urleror:”错误,但在Spyder内部运行时效果良好,python,urllib,Python,Urllib,所以我有一个脚本可以读取某些网站上的表格 当我在PythonIDE中运行这个脚本时,它工作得非常好。如果我尝试将其作为批处理文件独立运行,它将无法工作。它反映了以下错误: urllib.error.urleror: 你知道是什么引起的吗?我的剧本很短: # -*- coding: utf-8 -*- """ Created on Sun Aug 18 20:24:04 2019 @author: blueb """ import requests import numpy as np impo

所以我有一个脚本可以读取某些网站上的表格

当我在PythonIDE中运行这个脚本时,它工作得非常好。如果我尝试将其作为批处理文件独立运行,它将无法工作。它反映了以下错误: urllib.error.urleror:

你知道是什么引起的吗?我的剧本很短:

# -*- 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,请使用http。真正的问题是Python在环境中的安装[Breaked SSL]:

您是否构建了发生这种情况的Python环境?还是预先包装好的

>>> import ssl
ImportError: No module named ssl
在任何情况下,Spyder安装使用的Python解释器都没有使用正确的SSL支持进行编译,或者与系统的SSL不兼容。确保在安装Spyder之前安装SSL。以下是一些可以帮助您的资源:


在url中使用http并没有导致它。返回了相同的问题,因此看起来url正在自动重定向。你还有什么建议吗?我真的搞不懂这个链接。我担心你会被重定向到https,因为大多数网站现在都会这样做。让我把答案扩大一点。