python: 36 items found.

《无主之城》江雪反入侵之神秘脚本

最近看到国产网剧《无主之城》,感觉大有僵尸之类美剧的情节,看到第10集,江雪的电脑被入侵后,江雪在键盘上霹雳啪啦一顿狂操作,画面切到一堆黑屏的命令窗口,有点好奇是什么命令,遂暂停截了下图:

Screen Shot 2019-08-05 at 01.04.59.png

原来桌面用的黑色背景,命令窗口调用几个批处理命令打印出代码。代码的内容还是用Python的pygame库加载声音文件,设置音量。
而且几个窗口的内容是一样的!
和网络命令也不沾边,看来也就是做做效果,糊弄一下。

More ~

[python] 使用密码连接redis服务器 Connect redis with password

第一种方法:

rds = redis.StrictRedis(host='localhost', port=6379, password='123456')

第二种方法:

redis_config = {
        'host': os.getenv('REDIS_HOST', '127.0.0.1'),
        'port': os.getenv('REDIS_PORT', 6379),
        'password': os.getenv('REDIS_PWD', '123456')
    }
redis_uri = 'redis://:{password}@{host}:{port}/0'.format(**redis_config)
redis = Redis.from_url(redis_uri)
More ~

alpine based image to docker compose get error: command 'gcc' failed with exit status 1

Error like this:

Collecting misaka==2.1.1 (from -r requirements.txt (line 12))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fa/87/b1020510a00aba1b936477e54180b143df654c565b84936b0b3e85272cf2/misaka-2.1.1.tar.gz (125kB)
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: 
        No working compiler found, or bogus compiler options passed to
        the compiler from Python's standard "distutils" module.  See
        the error messages above.  Likely, the problem is not related
        to CFFI but generic to the setup.py of any Python package that
        tries to compile C code.  (Hints: on OS/X 10.8, for errors about
        -mno-fused-madd see http://stackoverflow.com/questions/22313407/
        Otherwise, see https://wiki.python.org/moin/CompLangPython or
        the IRC channel #python on irc.freenode.net.)
    
        Trying to continue anyway.  If you are trying to install CFFI from
        a build done in a different context, you can ignore this warning.
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.7/distutils/unixccompiler.py", line 118, in _compile
        extra_postargs)
      File "/usr/local/lib/python3.7/distutils/ccompiler.py", line 909, in spawn
        spawn(cmd, dry_run=self.dry_run)
      File "/usr/local/lib/python3.7/distutils/spawn.py", line 36, in spawn
        _spawn_posix(cmd, search_path, dry_run=dry_run)
      File "/usr/local/lib/python3.7/distutils/spawn.py", line 159, in _spawn_posix
        % (cmd, exit_status))
    distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

And my Dockerfile is here:

More ~

PyMongo使用密码连接Mongodb

以前的写法是这样的,

from pymongo import MongoClient
client = MongoClient(host='127.0.0.1')
db = client['dbname']
db.authenticate(user, password)

不过上面的已经废弃

warning:: Starting in MongoDB 3.6, calling :meth:authenticate
invalidates all existing cursors. It may also leave logical sessions
open on the server for up to 30 minutes until they time out.

More ~

No changes detected while running python manage.py makemigrations

Issues:

I want to recreate the migrations, so I deleted files under migrations folder, and drop the database. And try this python manage.py makemigrations, it reponse No changes detected.

Fix:

Create the database again, and clear files and folders under migrations, then try the following:

  1. python manage.py makemigrations --empty appname
  2. python manage.py makemigrations
  3. python manage.py migrate

It works!

More ~

Dockerfile指定pip安装源

Dockerfile使用的python3.7作为基础镜像 FROM python:3.7,但是执行
RUN pip install --no-cache-dir -r requirements.txt
是默认走了这个源,https://files.pythonhosted.org/packages,编译用时太久。

无赖修改成国内源来加快编译速度:
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -r requirements.txt

附国内其它源:
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

More ~