所以,我决定用python3编写我的下一个项目,为什么?由于Ubuntu计划在明年逐步放弃所有Python2支持并且只支持Python3.(从Ubuntu 13.04开始)
gevent和memcached模块没有正式移植到Python3.
对于gevent和pylibmc或python-memcached,有哪些替代品已经正式移植到Python3?
嗨其他程序员!
我正在尝试编写一个脚本,使用python和mechanize模块登录我的大学"食物平衡"页面...
这是我尝试登录的页面:http://www.wcu.edu/11407.asp 该网站有以下表格登录:
<FORM method=post action=https://itapp.wcu.edu/BanAuthRedirector/Default.aspx><INPUT value=https://cf.wcu.edu/busafrs/catcard/idsearch.cfm type=hidden name=wcuirs_uri>
<P><B>WCU ID Number<BR></B><INPUT maxLength=12 size=12 type=password name=id> </P>
<P><B>PIN<BR></B><INPUT maxLength=20 type=password name=PIN> </P>
<P></P>
<P><INPUT value="Request Access" type=submit name=submit> </P></FORM>
Run Code Online (Sandbox Code Playgroud)
据此我们知道我需要填写以下字段:1.name = id 2. name = PIN
通过操作:action = https://itapp.wcu.edu/BanAuthRedirector/Default.aspx
这是我到目前为止编写的脚本:
#!/usr/bin/python2 -W ignore
import mechanize, cookielib
from time import sleep
url = 'http://www.wcu.edu/11407.asp'
myId = '11111111111'
myPin = '22222222222'
# Browser
#br = mechanize.Browser()
#br = mechanize.Browser(factory=mechanize.DefaultFactory(i_want_broken_xhtml_support=True))
br = mechanize.Browser(factory=mechanize.RobustFactory()) # Use this because of bad …Run Code Online (Sandbox Code Playgroud) 以前,我在Django模板中设置了一个缓存的HTML块,如下所示.
{% load cache %}
{% cache 10000 courseTable %} <!-- Cached HTML --> {% endcache %}
Run Code Online (Sandbox Code Playgroud)
现在,我已更新此缓存内容并想要刷新它.我试着改变时间无济于事:
{% load cache %}
{% cache 0 courseTable %} <!-- Updated Cached HTML --> {% endcache %}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,页面仍然显示旧的缓存HTML.
我还尝试删除与缓存相关的模板标签并重新插入它们.但是,在这种情况下,重新插入缓存模板标记后,内容只会恢复为原始缓存的内容.
我能做什么?我不想等待大约2个小时来重新加载我的缓存.
我正在尝试增加Memcached安装中的最大项目大小。
到目前为止,我尝试过编辑/etc/memcached.conf添加行,-I 3M然后重新启动memcached。
这对我有用,但似乎在一夜之间恢复了。该设置仍然存在,但是当项目超过1MB时,将清除缓存。
您可以在此处看到我的原始问题Django Memcached缓存消失
我也尝试输入memcached -I 3m返回以下命令:
WARNING: Setting item max size above 1MB is not recommended!
Raising this limit increases the minimum memory requirements and will decrease your memory efficiency.
can't run as root without the -u switch
Run Code Online (Sandbox Code Playgroud)
随后运行memcached -Iu 3m返回:
Item max size cannot be less than 1024 bytes.
Run Code Online (Sandbox Code Playgroud)
我不知道这是什么意思,因为我试图增加最大大小而不是减小它,并且3MB肯定大于1024字节。我真的很受困,感谢所有帮助。谢谢。
更新:
在找到有关memcached的MySQL文档之后,我了解到-u标志的工作原理如下memcached -u root -I 3m。这会运行(仍然带有上面的警告),但随后会挂起。我一直盯着航站楼约10分钟,希望它能返回我的提示,但没有运气。请帮忙。
我有python-memcached(1.57)和django-celery(3.1.17),芹菜(3.1.20)和python 3.5.当我尝试实现http://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html#ensuring-a-task-is-only-executed-one-at-a时,我总是得到以下错误-时间
Task tasks.live_task[a2ed1faf-0fce-4855-a206-40f2fbdae1a8] raised unexpected: TypeError("a bytes-like object is required, not 'str'",)
Traceback (most recent call last):
File "/app/current/venv/lib/python3.5/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/app/current/venv/lib/python3.5/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/app/current/src/helps.py", line 62, in wrapper
if acquire():
File "/app/current/src/helps.py", line 57, in acquire
return cache.add(id, "true", time_out)
File "/app/current/venv/lib/python3.5/site-packages/django/core/cache/backends/memcached.py", line 80, in add
return self._cache.add(key, value, self.get_backend_timeout(timeout))
File "/app/current/venv/lib/python3.5/site-packages/memcache.py", line 633, in add
return self._set("add", key, val, …Run Code Online (Sandbox Code Playgroud) 我在Celery. 受此启发 - http://ask.github.io/celery/cookbook/tasks.html#ensuring-a-task-is-only-executed-one-at-a-time我决定使用 memcache 添加锁我的任务。
这些是我所做的更改:
python-memcached
# settings for memcache
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
Run Code Online (Sandbox Code Playgroud)
在此之后,我登录到我的 shell 并执行以下操作
>>> import os
>>> import django
>>> from django.core.cache import cache
>>> os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings.base')
>>> cache
<django.core.cache.DefaultCacheProxy object at 0x101e4c860>
>>> cache.set('my_key', 'hello, world!', 30) #display nothing. No T/F
>>> cache.get('my_key') #Display nothing.
>>> from django.core.cache import caches
>>> caches['default']
<django.core.cache.backends.memcached.MemcachedCache object at 0x1048a5208>
>>> caches['default'].set('my_key', 'hello, world!', 30) #display nothing. …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据这里的说明安装pylibmc:http://sendapatch.se/projects/pylibmc/install.html
我从这里下载了最新版本的pylibmc:http://pypi.python.org/pypi/pylibmc
我从这里下载了libmemcached(0.51):http://launchpad.net/libmemcached/1.0/0.51/+download/libmemcached-0.51.tar.gz
我正在运行Ubuntu 10.04,我也尝试在Debian Lenny VM上安装它.
这是我得到的错误:
atif@atif-laptop:~/pylibmc-1.2.2$ python setup.py install --with-libmemcached=/home/atif/libmemcached-0.51
running install
running build
running build_py
running build_ext
building '_pylibmc' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DUSE_ZLIB -I/home/atif/libmemcached-0.51/include -I/usr/include/python2.6 -c _pylibmcmodule.c -o build/temp.linux-i686-2.6/_pylibmcmodule.o -fno-strict-aliasing
In file included from _pylibmcmodule.c:34:
_pylibmcmodule.h:41:20: error: Python.h: No such file or directory
In file included from _pylibmcmodule.c:34:
_pylibmcmodule.h:85: error: expected specifier-qualifier-list before ‘PyObject’
_pylibmcmodule.h:103: error: expected specifier-qualifier-list before ‘PyObject’
_pylibmcmodule.h:111: …Run Code Online (Sandbox Code Playgroud) 我正在为我的Django应用程序使用Memcache.
在Django中,开发人员可以使用模板片段缓存来仅缓存模板的一部分.https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching
我想知道是否有一种方法可以在views.py中明确更改模板片段缓存部分的值.例如,除了模板片段缓存之外,可以使用类似于cache.set("sidebar","new value")的方法吗?
谢谢您的帮助.
是否有一些现成的插件可以提醒管理员有关memcached实例无法从Django应用程序访问的内容?我不是指监视memcached守护进程本身,而是检查我的Django应用程序是否从缓存中获益.
我的基本想法是检查cache.set后面的cache.get是否实际返回了一些东西,如果没有 - 然后发送电子邮件给管理员,但每小时只发送一封,以免淹没收件箱.
但也许有更先进的东西?
我有一个谷歌应用程序引擎应用程序(使用python创建).我想为memcache添加一个值,但希望每个午夜(PST)的值到期如何执行此操作?
python-memcached ×10
django ×5
memcached ×5
python ×5
django-cache ×3
celery ×2
caching ×1
gevent ×1
login-script ×1
mechanize ×1
python-3.x ×1
ubuntu ×1