简体   繁体   English

Python httplib2访问被拒绝

[英]Python httplib2 Access is denied

I am facing a problem on executing simple code. 我在执行简单代码时遇到问题。

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

Output is 输出是

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'

Anyone with any suggestions to fix this error? 有人对解决此错误有任何建议吗?

To get this working you could just leave out the cache directory: 要使此工作正常进行,您可以仅删除缓存目录:

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

As the comments say above, you don't have permission to create the .cache directory relative to the path you're running the code from. 正如上面的评论所述,您.cache相对于您从中运行代码的路径创建.cache目录。

Of course, having a cache is better... 当然,拥有缓存会更好...

For a simple, in-memory cache which won't cause you permissions headaches, checkout this article I wrote: http://grahamlyons.com/article/a-simple-in-memory-cache-for-python-s-httplib2 对于不会导致权限麻烦的简单的内存中缓存,请查看我写的这篇文章: 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