簡體   English   中英

Python httplib2訪問被拒絕

[英]Python httplib2 Access is denied

我在執行簡單代碼時遇到問題。

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'

有人對解決此錯誤有任何建議嗎?

要使此工作正常進行,您可以僅刪除緩存目錄:

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

正如上面的評論所述,您.cache相對於您從中運行代碼的路徑創建.cache目錄。

當然,擁有緩存會更好...

對於不會導致權限麻煩的簡單的內存中緩存,請查看我寫的這篇文章: http : //grahamlyons.com/article/a-simple-in-memory-cache-for-python-s-httplib2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM