我有一个Python脚本,该脚本在Windows服务器上运行得很好,但是在Ubuntu 16.04.5上运行时抛出SSLError异常。
我已使用pygsheets
连接到Google工作表。
import pygsheets
from oauth2client.service_account import ServiceAccountCredentials
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive'
]
credentials01 = ServiceAccountCredentials.from_json_keyfile_name('creds01.json', scope)
credentials02 = ServiceAccountCredentials.from_json_keyfile_name('creds02.json', scope)
file01 = pygsheets.authorize(credentials=credentials01)
file02 = pygsheets.authorize(credentials=credentials02)
wb01 = file01.open('Database System 2')
wb02 = file02.open('Database System 2')
if __name__ == '__main__':
manager = multiprocessing.Manager()
output_dfs = manager.list()
new_dfs_dict = manager.dict()
for l in main_list:
for i in range(0, len(l[0]), 5):
processes = []
ids_sublist = []
for j in range(i, i + 5):
try:
ids_sublist.append(l[0][j])
except:
pass
for ID in ids_sublist:
processes.append(multiprocessing.Process(target=fetch_data, args=(ID, start_date, end_date, new_dfs_dict, output_dfs)))
for p in processes:
p.start()
for p in processes:
p.join()
for ID in l[0]:
if not l[1].empty:
cols_list = list(l[2][ID].columns)
cols_list.remove('Type')
cols_list[1:1] = ['Type']
l[2][ID] = l[2][ID][cols_list]
l[2][ID].update(new_dfs_dict[ID])
l[2][ID] = pd.merge(l[2][ID], new_dfs_dict[ID])
else:
l[2][ID] = new_dfs_dict[ID]
ready_to_set_df = pd.DataFrame()
for ID in l[2]:
ready_to_set_df = pd.concat([ready_to_set_df, l[2][ID]], sort=False)
output_sheet = wb01.worksheet_by_title(l[3])
output_sheet.clear()
output_sheet.set_dataframe(ready_to_set_df.fillna(0), 'A1')
output_df = pd.DataFrame(columns=bank_portal_data_header)
for df in output_dfs:
output_df = output_df.append(df)
try:
data_sheet = wb02.worksheet_by_title(end_date)
data_df = data_sheet.get_as_df(has_header=True)
output_df = data_df[bank_portal_data_header].append(output_df)
output_df = output_df.drop_duplicates(keep=False)
data_sheet.clear()
data_sheet.set_dataframe(output_df, 'A1', copy_head=True)
except:
data_sheet = wb02.add_worksheet(end_date)
data_sheet.set_dataframe(output_df, 'A1', copy_head=True)
它将SSLError抛出在data_sheet.clear()
奇怪的是,脚本可以在Windows Server上完美运行。谢谢
答案 0 :(得分:0)
我会尝试更新ca-certificates
。该信息取自Adding CAcert root certificate to Debian/Ubuntu:
# first make a directory in which to store the CAcert certificate files.
sudo mkdir /usr/local/share/ca-certificates/cacert.org
# Download the root certificates from the --> http://www.cacert.org
sudo wget -P /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt
# update certificate bundle
sudo update-ca-certificates