• 首页
  • Android
  • Java
  • Python
  • 信息安全
  • 闲扯淡

Guge's blog

以大多数人的努力程度之低,根本轮不到去拼天赋

Python

Sublime Text2 python调试 显示空白的解决办法

2016年1月26日 by Guge Leave a Comment

配置好Python环境后,修改sublime的python配置文件(Python.sublime-build),将内容改为:

{
“cmd”: [“python”, “-u”, “$file”],
“path”:”C:/Python27″,
“file_regex”: “^[ ]*File \”(…*?)\”, line ([0-9]*)”,
“selector”: “source.python”
}

主要是第2行内容,加入Windows环境下的python路径

然后Ctrl+B,调试python发现是空白,调出控制台(Ctrl+`),显示如下错误:

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc0 in position 9: ordinal not in range(128)

这个问题的起因是配置文件目录下Packages\Default目录下的exec.py在编辑环境变量,但是环境变量中的字符集缺少了ascii字符集。

解决办法:

找到配置文件目录位置(在sublime text 2中点Preference -> Browse Packages)在Default目录下找到exec.py,编辑;

找到以下两行:

1
2
        for k, v in proc_env.iteritems():
proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())

更改为:

1
2
3
4
5
6
        for k, v in proc_env.iteritems():
try:
proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())
except UnicodeDecodeError:
print(“Encoding error”)
print(“VARIABLE: “, k, ” : “, v)

OK。

Posted in: Python Tagged: python, sublime text2

PhantomJS安装折腾记

2015年3月6日 by Guge Leave a Comment

build是非常漫长过程,其中还会提示你有哪些支持未安装:

23

之前解决了ICU的问题,按照官方说明,又一并安装了如下支持包:

Shell
1
2
3
#sudo apt-get install build-essential g++ flex bison gperf ruby perl \
  libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \
  libpng-dev libjpeg-dev

然后再次./build.sh,终于顺利通过。

2.0貌似有BUG,依然无法顺利安装,最终通过

Python
1
sudo apt-get install phantomjs

安装了1.9版本。

Posted in: Python Tagged: Phantomjs

PhantomJS ICU disabled解决

2015年3月6日 by Guge Leave a Comment

需要安装libicu developer依赖:

Python
1
#apt-get install libicu-dev

 

Posted in: Python Tagged: ICU, Phantomjs

Linux安装PhantomJS2.0

2015年3月6日 by Guge Leave a Comment

网上很多教程都是使用wget的方式安装PhantomJS1.97版本的,目前最近是2.0版本,并且已将程序迁移至GitHub,按照官网说明,只需3步就可搞定:

Shell
1
2
3
4
#git clone git://github.com/ariya/phantomjs.git
#cd phantomjs
#git checkout 2.0
#./build.sh

安装过程比较长,并且对CPU的占用很高,可以使用./build.sh --jobs 1命令来降低程序安装时对系统性能的占用影响。

Posted in: Python Tagged: git, Phantomjs

django后台管理界面添加中文内容报Incorrect string value错误的解决方法

2015年2月11日 by Guge Leave a Comment
参照“虫师”的博文,配置django,在后台输入中文内容时,出现报错。
报错内容大致为:
Incorrect string value: '\xE5\x93\x88\xE5\x93\x88...' for column 'title' at row 1
Request Method: POST
Request URL:    http://127.0.0.1:8000/admin/blog/blogspost/add/
Django Version: 1.7.4
Exception Type: Warning
数据库为Mysql数据库,查看了数据库中数据列的格式,需要将其设置为utf8格式就OK,命令如下:
Shell
1
2
mysql> alter table test change title title varchar(150) character set utf8;
mysql> alter table test change body body longtext character set utf8;

1

 

Posted in: Python Tagged: admin, django, MySQL, utf8, 中文

Python每日一题(第0005题)

2015年2月6日 by Guge Leave a Comment

题目:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小。

代码:前提,必须安装PIL库

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding:utf-8 -*-
 
'''
批量修改文件中的图片为格式及大小
 
'''
 
import os, glob
import Image
 
 
 
path = raw_input("path:")
width =int(raw_input("the width U want:"))
imgslist = glob.glob(path+'/*.*')
format = raw_input("format:")
def small_img():
for imgs in imgslist:
imgspath, ext = os.path.splitext(imgs)
print imgs
img = Image.open(imgs)
(x,y) = img.size
print x,y
height =int( y * width /x)
print height
small_img =img.resize((width,height),Image.ANTIALIAS)
small_img.save(imgspath +".thumbnail."+format)
print "done"
 
if __name__ == '__main__':
small_img()

 

Posted in: Python Tagged: python每日一题, 图片大小, 格式, 调整

Python每日一题(第0002题)

2015年2月5日 by Guge Leave a Comment

题目:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#coding=utf-8
import MySQLdb
import random,string
 
 
def password(len):
chars = string.ascii_letters.lower() + string.digits
return ''.join(random.sample(chars,len))
 
def insertcdkey():
number = 1
for i in range (200):
passwd = password(10)
cur.execute('insert into jihuoma (id, cdkey) values (%s, %s)', [number, passwd])
number += 1
#print number,passwd
 
if __name__ == '__main__':
conn = MySQLdb.connect(
host = 'localhost',
    port = 3306,
    user = 'root',
    passwd = '',
    db = 'test')
cur = conn.cursor()
cur.execute("create table jihuoma(id varchar(20) primary key,cdkey varchar(20))")
insertcdkey()
cur.close()
conn.commit()
conn.close()

笔记:MySQL的SQL占位符是%s;

Posted in: Python Tagged: MySQL, MySQLdb, 占位符, 数据库

python操作Mysql数据库

2015年1月27日 by Guge Leave a Comment

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#coding=utf-8
import MySQLdb
 
conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='123456',
        db ='test',
        )
cur = conn.cursor()
 
#创建数据表
#cur.execute("create table student(id int ,name varchar(20),class varchar(30),age varchar(10))")
 
#插入一条数据
#cur.execute("insert into student values('2','Tom','3 year 2 class','9')")
 
 
#修改查询条件的数据
#cur.execute("update student set class='3 year 1 class' where name = 'Tom'")
 
#删除查询条件的数据
#cur.execute("delete from student where age='9'")
 
cur.close()
conn.commit()
conn.close()

PS:由于Kali已安装了MySQL-python,故无需安装,如在Python下,输入

Python
1
>>> import MySQLdb

报错提示模块找不到,则需要安装MySQL-python:

下载地址:https://pypi.python.org/pypi/MySQL-python/

下载MySQL-python-1.2.5.zip 文件之后直接解压,然后进入目录安装即可:

>>python setup.py install

Posted in: Python Tagged: MySQL, MySQL-Python, 数据库

Python每天一个小程序(第1题)

2014年12月25日 by Guge Leave a Comment

题目要求:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?

思路:Apple Store App的激活码(优惠券)一般长度为10位,由小写字母与数字组成,因此需要用到Python中的random和string库。
代码:

Python
1
2
3
4
5
6
7
8
9
import random,string
 
def passwords(len):
chars = string.ascii_letters.lower() + string.digits
# return ''.join([random.choice(chars) for i in range(len)]) #得出的结果中会有重复
return ''.join(random.sample(chars,len))
if __name__ == '__main__':
for j in range(200):
print passwords(10)

 

Posted in: Python Tagged: random, string, 优惠券, 每天一个小程序, 激活码

Python每天一个小程序(第0题)

2014年12月23日 by Guge Leave a Comment

题目要求:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于下图效果:

687474703a2f2f692e696d6775722e636f6d2f736732646b75592e706e673f31

思路:

1.使用PIL库

2.对本地图片读入,然后添加要写的文本内容

3.另存一张图片到本地,完成

代码:

Python
1
2
3
4
5
6
7
8
9
10
# -*- coding: utf-8 -*- #文件也为UTF-8
#!/usr/bin/env python
from PIL import Image,ImageDraw,ImageFont
 
txt = "1" #要在图片上添加的内容
image = Image.open('112.jpg')#打开本地图片
draw = ImageDraw.Draw(image)
font = ImageFont.truetype('/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf',19) #字体与大小设置
draw.text((170,10), txt,(250,0,0),font=font)#第一个参数为文字位置,第二个参数为文字的RGB颜色设置
image.save('new.jpg') #另存

结果:

QQ圖片20141223162139

Posted in: Python Tagged: 每天一个小程序
1 2 3 下一页 »

微信公众平台

站内搜索

标签

360 Activity ADB Android android studio apktool arm BCTF CSRF CTF drozer hacker精神 IDA ISG java线程 Json Launch4j MySQL ndk Phantomjs python ROP xposed xss Zaker 一周安全 信息安全 信息安全,干货 加壳 华尔街之狼 安全 安全干货 安全竞赛 寄存器 干货 数据库 查找 步长 每天一个小程序 爬虫 程序员 系统信息获取 脱壳 逆向 遍历

近期文章

  • 关于绕过域名(ip)的一些小技巧
  • 骨哥电台第4期:马斯克之地启示录1
  • 骨哥电台第3期:了解马斯克
  • 骨哥电台第2期:钢铁侠原型-霍华德·休斯的故事
  • 它终于让我换下了使用多年的谷歌浏览器

友情链接

CRoot' Blog
void* Future

Copyright © 2021 Guge's blog.

Omega WordPress Theme by ThemeHall