今天准備測試代理池IPProxyPool獲取到ip的質量,在安裝web.py的時候遇到了些問題,在此記錄一下。
1.安裝資料
web.py官網:http://webpy.org/
web.py的github地址:https://github.com/webpy/webpy/
2.安裝
方法1:(推薦)
pip install web.py==0.40-dev1
方法2:
注意:這個是使用linux軟連接方式
git clone git://github.com/webpy/webpy.git ln -s `pwd`/webpy/web .
方法3(從源碼處安裝):
git clone https://github.com/webpy/webpy.git cd webpy python setup.py install
pip list
3.問題
3.1.python2與python3問題
pip install web.py
上面安裝命令只支持python2,官網上已經說明過。這樣安裝會報錯:
ERROR: Command errored out with exit status 1: command: 'e:\program\python\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\peng\\AppData\\Local\\Temp\\pip-install-ubdky_a3\\web.py\\setup.py'"'"'; __file__='"'"'C:\\Users\\peng\\AppData\\Local\\Temp\\pip-install-ubdky_a3\\web.py\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info cwd: C:\Users\peng\AppData\Local\Temp\pip-install-ubdky_a3\web.py\ Complete output (7 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\peng\AppData\Local\Temp\pip-install-ubdky_a3\web.py\setup.py", line 6, in <module> from web import __version__ File "C:\Users\peng\AppData\Local\Temp\pip-install-ubdky_a3\web.py\web\__init__.py", line 14, in <module> import utils, db, net, wsgi, http, webapi, httpserver, debugerror ModuleNotFoundError: No module named 'utils' ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
主要是這個錯誤:
Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\peng\AppData\Local\Temp\pip-install-ubdky_a3\web.py\setup.py", line 6, in <module> from web import __version__ File "C:\Users\peng\AppData\Local\Temp\pip-install-ubdky_a3\web.py\web\__init__.py", line 14, in <module> import utils, db, net, wsgi, http, webapi, httpserver, debugerror ModuleNotFoundError: No module named 'utils'
原因是,除了0.40-dev1版本支持python3外其他版本都不支持(測試過webpy-0.39)
github上的版本:https://github.com/webpy/webpy/tags
3.2.測試hello world出錯
官網例子:
import web urls = ( '/(.*)', 'hello' ) app = web.application(urls, globals()) class hello: def GET(self, name): if not name: name = 'World' return 'Hello, ' + name + '!' if __name__ == "__main__": app.run()
錯誤:
Traceback (most recent call last): File "E:\Program\python\lib\site-packages\web\utils.py", line 526, in take yield next(seq) StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File ".\test_web.py", line 6, in <module> app = web.application(urls, globals()) File "E:\Program\python\lib\site-packages\web\application.py", line 62, in __init__ self.init_mapping(mapping) File "E:\Program\python\lib\site-packages\web\application.py", line 130, in init_mapping self.mapping = list(utils.group(mapping, 2)) File "E:\Program\python\lib\site-packages\web\utils.py", line 531, in group x = list(take(seq, size)) RuntimeError: generator raised StopIteration
解決方法:
修改Lib\site-packages\web 下的utils.py文件,在526行
源碼:
def take(seq, n): for i in range(n): yield next(seq)
修改后:
def take(seq, n): for i in range(n): try: yield next(seq) except StopIteration: return
運行: