首页 > 解决方案 > 如何处理 UFuncTypeError?

问题描述

运行此程序时出现此错误:
UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U21'), dtype('<U21')) -> dtype('<U21' )

import requests
import numpy as np
username ='xxxxxx'
password ='yyyyyy'
years = np.arange(1961,1967)
for year in years:
    url = 'http://aphrodite.st.hirosaki-u.ac.jp/product/APHRO_V1808_TEMP/APHRO_MA/050deg_nc/APHRO_MA_TAVE_050deg_V1808.'+ str(year)+'.nc.gz'
    r=requests.get(url,auth=(username,password),allow_redirects=True)
    open(str(year+'.gz','wb').write(r.content))  

谁能帮助如何消除此错误?我正在尝试从网站下载一个大型数据集。

标签: pythonnumpydataset

解决方案


你的最后一行应该是

open(str(year) + 'gz', 'wb').write(r.content)

推荐阅读