Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1087063
  • 博文数量: 321
  • 博客积分: 7872
  • 博客等级: 少将
  • 技术积分: 2120
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-16 09:06
文章分类

全部博文(321)

文章存档

2017年(1)

2016年(1)

2015年(12)

2014年(17)

2013年(78)

2012年(15)

2011年(17)

2010年(67)

2009年(102)

2008年(11)

分类: LINUX

2015-08-14 10:54:49

How to install bypy on VPS?

bypy is a Python client for Baidu Yun.

Step 1: Upgrade python to 2.7

My VPS is a 64bit Centos 6.4 and Python2.6.6 was installed by default.

 
1
				
2
3
4
5
6
				
				
[root@huzhifeng bypy]# uname -a
Linux huzhifeng.com 2.6.32-042stab084.20 #1 SMP Thu Apr 3 17:41:05 MSK 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@huzhifeng bypy]
[root@huzhifeng ~]# python -V
Python 2.6.6
[root@huzhifeng ~]

首先参考Centos 6.4 python 2.6 升级到 2.7
下载Python-2.7.3,解压,安装,覆盖旧版本:

 
1
				
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
				
				
[root@huzhifeng work]# wget --no-check-certificate
[root@huzhifeng work]# tar xjf Python-2.7.3.tar.bz2
[root@huzhifeng work]# cd Python-2.7.3
[root@huzhifeng Python-2.7.3]# ./configure
[root@huzhifeng Python-2.7.3]# make
[root@huzhifeng Python-2.7.3]# make install
[root@huzhifeng Python-2.7.3]# ls /usr/local/bin/python* -l
lrwxrwxrwx 1 root root 7 May 4 09:17 /usr/local/bin/python -> python2
lrwxrwxrwx 1 root root 14 May 4 09:17 /usr/local/bin/python-config -> python2-config
lrwxrwxrwx 1 root root 9 May 4 09:17 /usr/local/bin/python2 -> python2.7
lrwxrwxrwx 1 root root 16 May 4 09:17 /usr/local/bin/python2-config -> python2.7-config
-rwxr-xr-x 1 root root 6162209 May 4 09:17 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root 1624 May 4 09:17 /usr/local/bin/python2.7-config
[root@huzhifeng Python-2.7.3]# mv /usr/bin/python /usr/bin/python2.6.6
[root@huzhifeng Python-2.7.3]# cp /usr/local/bin/python2.7 /usr/bin/python
[root@huzhifeng Python-2.7.3]# python -V
Python 2.7.3
[root@huzhifeng Python-2.7.3]#

Step 2: Install pip for Python2.7.3

Instal pip
Download get-pip.py

 
1
				
2
3
				
				
[root@huzhifeng Python-2.7.3]# wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O get-pip.py
[root@huzhifeng Python-2.7.3]# python get-pip.py
[root@huzhifeng Python-2.7.3]# pip install requests

Step 3: 把系统的区域编码设置为UTF-8

Centos设置zh_CN.UTF-8
查看locale并设置loacle为UTF-8中文环境,注意,修改后需要重新连接或者新建终端才会生效。

	
				
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
				
				
[root@huzhifeng Python-2.7.3]# locale -a |grep zh
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.big5hkscs
zh_HK.utf8
zh_SG
zh_SG.gb2312
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.big5
zh_TW.euctw
zh_TW.utf8
[root@huzhifeng Python-2.7.3]# vim /etc/sysconfig/i18n
LANG="zh_CN.utf8"
SYSFONT=latarcyrheb-sun16

Step 4: Git clone bypy,生成token并使用bypy

	
				
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
32
33
34
35
36
37
38
39
				
				
[root@huzhifeng work]# git clone
[root@huzhifeng work]# cd bypy/
[root@huzhifeng bypy]# ls
LICENSE README.md bypy.py bypygui.pyw
[root@huzhifeng bypy]# ./bypy.py info
Token file: '/root/.bypy.json'
Hash Cache file: '/root/.bypy.pickle'
App root path at Baidu Yun '/apps/bypy'
sys.stdin.encoding = ANSI_X3.4-1968
sys.stdout.encoding = ANSI_X3.4-1968
----
<E> [09:39:51] Error while loading baidu pcs token:
<E> [09:39:51] Traceback (most recent call last):
File "./bypy.py", line 1046, in __load_local_json
with open(TokenFilePath, 'rb') as infile:
IOError: [Errno 2] No such file or directory: u'/root/.bypy.json'
Please visit:
https://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&redirect_uri=oob&response_type=code&client_id=q8WE4EpCsau1oS0MplgMKNBn
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done
... <--- Here is the authorization code
Authorizing, please be patient, it may take upto 60.0 seconds...
Successfully authorized
Quota: 2.103TB
Used: 1.61TB
[root@huzhifeng bypy]# ./bypy.py info
Token file: '/root/.bypy.json'
Hash Cache file: '/root/.bypy.pickle'
App root path at Baidu Yun '/apps/bypy'
sys.stdin.encoding = UTF-8
sys.stdout.encoding = UTF-8
----
Quota: 2.103TB
Used: 1.61TB
[root@huzhifeng bypy]#

现在自动在网盘下目录“我的应用数据”下新建了一个文件夹“bypy”,目录为空,拷贝几张图片进去,然后用bypy.py list查看

 
1
				
2
3
4
5
6
7
8
9
10
11
12
13
14
15
				
				
[root@huzhifeng bypy]# ./bypy.py list
Token file: '/root/.bypy.json'
Hash Cache file: '/root/.bypy.pickle'
App root path at Baidu Yun '/apps/bypy'
sys.stdin.encoding = UTF-8
sys.stdout.encoding = UTF-8
----
/apps/bypy ($t $f $s $m $d):
F IMG_8143.jpg 3271156 2014-05-04, 09:55:36 b239d689b6ca306d2931a99b3873a19e
F IMG_8176.jpg 3278269 2014-05-04, 09:55:36 1b63f3233b55f5d956accf69aebabc28
F IMG_8240.jpg 3529871 2014-05-04, 09:55:36 f723a61d988d8d2a751c27301e14ff32
F IMG_8328.jpg 2523040 2014-05-04, 09:55:36 937a6137d09acd8951a7d163ed503798
F IMG_8361.jpg 3247336 2014-05-04, 09:55:36 04efab7ef97d2c7f872793d090aec197
[root@huzhifeng bypy]#

EOF

转自:管理员在2009年8月13日编辑了该文章文章。

-->
阅读(5032) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~