2013-03-08 108 views
0

我在執行簡單代碼時遇到問題。Python httplib2訪問被拒絕

import httplib2 
h = httplib2.Http(".cache") 
resp, content = h.request("http://example.org/", "GET") 

輸出是

Traceback (most recent call last): 
    File "<interactive input>", line 1, in <module> 
    File "C:\Python27\lib\site-packages\httplib2\__init__.py", line 1175, in __init__ 
    self.cache = FileCache(cache) 
    File "C:\Python27\lib\site-packages\httplib2\__init__.py", line 700, in __init__ 
    os.makedirs(self.cache) 
    File "C:\Python27\lib\os.py", line 157, in makedirs 
    mkdir(name, mode) 
WindowsError: [Error 5] Access is denied: '.cache' 

任何人只要有任何建議,以解決這個錯誤?

+2

它看起來像你無法在工作目錄中創建.cache目錄。也許切換你的當前目錄修復它。 – 2013-03-11 18:58:33

+1

您是否有權限創建腳本正在執行的文件夾? – 2013-03-11 18:59:09

+0

很確定這是一個權限問題... – summea 2013-03-11 18:59:31

回答

1

爲了得到這個工作,你可能只是離開了緩存目錄:

import httplib2 
h = httplib2.Http() 
resp, content = h.request("http://example.org/", "GET") 

正如評論說以上,你沒有權限創建相對於您正在運行的路徑.cache目錄代碼來自。

當然,有一個緩存比較好...

對於簡單的,內存緩存,這將不會導致你的權限頭痛,結帳這篇文章中我寫道:http://grahamlyons.com/article/a-simple-in-memory-cache-for-python-s-httplib2