1. 程式人生 > >[python錯誤]builtins.AttributeError: 'module' object has no attribute 'request'

[python錯誤]builtins.AttributeError: 'module' object has no attribute 'request'

在python3.4.3版本下,使用wingIDE寫爬蟲的時候,

發生了builtins.AttributeError: 'module' object has no attribute 'request'的錯誤。

錯誤來源是程式碼中的

<span style="font-size:18px;">request = urllib.request.Request(url)</span>

【解決方案】

import的時候直接用urllib.request,而不是import urllib。

同理,使用

except  urllib.error.URLError as e:

遇到builtins.AttributeError: 'module' object has no attribute 'error'的時候,直接import urllib.error就可以解決!

相關推薦

[python錯誤]builtins.AttributeError: 'module' object has no attribute 'request'

在python3.4.3版本下,使用wingIDE寫爬蟲的時候, 發生了builtins.AttributeError: 'module' object has no attribute 'request'的錯誤。 錯誤來源是程式碼中的 <span style="fo

Python錯誤AttributeError: module 'signal' has no attribute 'SIGALRM'

電腦系統是win10 64位,在使用python的signal模組時報錯:“AttributeError: module 'signal' has no attribute 'SIGALRM'”,這是因為signal模組可以在linux下正常使用,但在windows下卻有一些

針對AttributeError: ‘moduleobject has no attribute’xxx’的錯誤歸類

找不到 with 類型 error: 開頭 -a 發現 使用 def 目前遇見的有三種類型: 拼寫錯誤,模塊一定要拼寫錯誤,這個也是最容易犯的,發現找不到模塊的時候,最好先檢查一遍自己引入的模塊拼寫尤其是那些名字非常長的比如HTTPPasswordMgrWithDefau

python AttributeError: 'module' object has no attribute 'setdefaultencoding'

window下使用python,AttributeError: 'module' object has no attribute 'setdefaultencoding'問題的解決方法 參閱了http://www.jb51.net/article/54159.htm後進行整

Python指令碼報錯AttributeError: ‘moduleobject has no attribute’xxx’解決方法

最近在編寫Python指令碼過程中遇到一個問題比較奇怪:Python指令碼完全正常沒問題,但執行總報錯"AttributeError: 'module' object has no attribute 'xxx'"。這其實是.pyc檔案存在問題。 問題定位:

Python 3.x中使用urllib出現AttributeError: module 'urllib' has no attribute 'request'錯誤

剛剛開始學習爬蟲,開始寫部落格打算把錯誤記錄下來,已杜自己忘記,並給同樣的小白幫助python 3.x中urllib庫和urilib2庫合併成了urllib庫,python3.X中應該使用urllib.request,即替換掉(python中的)urllib2成urllib.

python學習筆記(2)】指令碼報錯"AttributeError: 'module' object has no attribute 'xxx'"解決方法

最近在編寫Python指令碼過程中遇到一個問題比較奇怪:Python指令碼完全正常沒問題,但執行總報錯"AttributeError: 'module' object has no attribute 'xxx'"。這其實是.pyc檔案存在問題。 問題定位: 檢視imp

AttributeError: 'module' object has no attribute 'post'問題

在學習python網頁爬蟲時,測試requests的post方法進行表單提交時,命名.py檔案為requests.py 程式碼如下: import requests params={'firstname':'xing','lastname':'ming'

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

編譯環境:python 3.1.2 測試程式: # coding = utf-8 import urllib def getHtml(url):     page = urllib.

報錯 AttributeError: 'module' object has no attribute 'bool_'

在使用import numpy時突然出現如下報錯: 出現AttributeError: ‘module’ object has no attribute ‘bool_’報錯. 解決辦法: **因為昨晚安裝caffe,但make報錯就沒有繼續,電腦裡已安

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

使用tf.select函數出現錯誤, AttributeError: ‘module’ object has no attribute ‘select’ 這是因為當前版本tensorflow無tf.select函式,可以改為使用函式tf.where

pycharm 安裝第三方庫報錯:AttributeError: 'module' object has no attribute 'main'

pip升級到 10.0.1 之後 老版的pycharm 使用pip安裝第三方庫的時候會報錯,報錯如上圖所示: 其主要原因是 新版的 pip 更改了 部分api 將其中 pip.main() 改為 pip_main(), 舊版的pycharm中 在packagi

import json後,報錯:AttributeError: 'module' object has no attribute 'dumps,原因分析及解決方法

編寫python程式碼,import json後,報錯:AttributeError: 'module' object has no attribute 'dumps',如下圖所示: 報錯資訊為:模組沒有方法dumps 單步除錯: 單步除錯,發現報錯相同。 檢視json

TensorFlow執行錯誤AttributeError: module 'pandas' has no attribute 'computation'

TensorFlow執行錯誤,AttributeError: module ‘pandas’ has no attribute ‘computation’ 在我今天剛開始使用TensorFlow做數字識別時,在匯入input_data方法時,即是執行“from

關於 AttributeError: module 'urllib' has no attribute 'request' 的引包範圍問題

今天在使用python進行爬蟲的時候,遇到了一個小問題:AttributeError: module 'urllib' has no attribute 'request' AttributeError: module 'urllib' has no attribute 'p

Python 在import時明明寫的正確,卻提示錯誤AttributeError: module 'test003' has no attribute 'desc'

在自己寫一個小專案的時候,發現明明自己使用import引入自己專案中的另一個Python檔案是正確的寫法,在執行的時候卻發現總是提示錯誤。因為筆者本人也是學習Python不久,經過一個小時的琢磨,感覺應該是兩個檔案迴圈引用導致錯誤。比如一個a.py在使用的時候需要引用b.py

AttributeError:’moduleobject has no attribute ‘ifelse’錯誤資訊的解決方法

在執行訓練卷積神經網路CNN模型進行分類的Python程式碼過程中,出現如下錯誤資訊: AttributeError:’module’object has no attribute ‘ifelse’

pytorch低版本載入高版本pytorch訓練得到的模型,出現‘moduleobject has no attribute ‘_rebuild_tensor_v2’錯誤

情景 使用pytorch0.3來載入Mobilenetv1的模型(用更高版本的pytorch訓練得到的),出現“AttributeError: ‘module’ object has no attrib

python AttributeError module 'string' has no attribute 'upp

                Traceback (most recent call last):  File "Test1.py", line 8, in <module>    upperletters = string.uppercaseAttributeError: module 'st

Python3.X出現AttributeError: module 'urllib' has no attribute 'urlopen'錯誤

研究用Python寫爬蟲,下載一個網頁。報錯程式碼如下 import urllib def getHtml(url): page = urllib.urlopen(url) html = page.read() return html html