2017-02-24 152 views
1

我對python非常陌生並且在練習從URL加載數據集Python:屬性錯誤:'模塊'對象沒有'請求'屬性

當運行以下代碼:

[1]:myUrl = 「http://aima.cs.berkeley.edu/data/iris.csv
[2]:的URLRequest = urllib.request.Request(myUrl)

我得到這個錯誤:

File "", line 1, in urlRequest = urllib.request.Request(myUrl)

AttributeError: 'module' object has no attribute 'request'

1)我試圖研究這個錯誤,並試圖再次使用import urllib3,它導入罰款。嘗試我得到這個錯誤的請求......

2)然而,當我試圖在Python 3.6.0獲得 「幫助」 help("urllib3"),並得到:

No Python documentation found for 'urllib3'. Use help() to get the interactive help utility. Use help(str) for help on the str class.

3)我搜索#1並看到了類似的問題;嘗試了這些建議,並沒有能夠通過該代碼行...

我在這裏做錯了什麼?

預先感謝您的時間

回答

2

從我所看到的「請求」是不是一個包,這意味着你不能直接從它導入類。

嘗試:

from urllib.request import Request 
myUrl = "http://aima.cs.berkeley.edu/data/iris.csv" 
urlRequest = Request(myUrl) 
+0

您還可以使用「導入urllib.request裏」,然後使用「urllib.request.Request」,但它更簡潔這樣 – LoicM

+0

謝謝...制定出...非常感謝... – Kevin

+0

很高興聽到!請考慮[接受它](http://stackoverflow.com/help/accepted-answer),以便它有助​​於引用具有相同問題的其他用戶。 – LoicM

相關問題