csv PyCharm v4.5无法导入名称“request”

hsgswve4  于 2023-06-19  发布在  PyCharm
关注(0)|答案(1)|浏览(116)

每当我运行这段代码时:

from urllib import request

goog_url = 'http://real-chart.finance.yahoo.com/table.csv?s=TSLA&d=4&e=20&f=2015&g=d&a=5&b=29&c=2010&ignore=.csv'

def download_stock_data(csv_url):

    response = request.urlopen(csv.url)
    csv = response.read()
    csv_str = str(csv)
    lines = csv_str.split("\\n")
    dest_url = r'goog.csv'
    fx = open(dest_url, "w")
    for line in lines:
        fx.write(line + "\n")
    fx.close()

download_stock_data(goog_url)

我得到这个错误:

C:\Python27\python.exe C:/Users/Luke/PycharmProjects/untitled2/main.py
Traceback (most recent call last):

  File "C:/Users/Luke/PycharmProjects/untitled2/main.py", line 1, in <module>
    from urllib import request

ImportError: cannot import name request

我试过安装'request'模块,但安装总是失败。我做错了什么?我对这个东西很陌生,但我已经尝试了一堆其他可能的解决方案,我发现在这里没有任何成功。

zaq34kh6

zaq34kh61#

试试用

from urllib3 import request

适用于Python 2.7

相关问题