小编hal*_*tTm的帖子

Python中的ZipFile模块出现错误的幻数错误

我在Windows 7(64位)上使用Python 2.7.当我尝试用ZipFile模块解压缩zip文件时,我收到以下错误: -

Traceback (most recent call last):
  File "unzip.py", line 8, in <module>
    z.extract(name)
  File "C:\Python27\lib\zipfile.py", line 950, in extract
    return self._extract_member(member, path, pwd)
  File "C:\Python27\lib\zipfile.py", line 993, in _extract_member
    source = self.open(member, pwd=pwd)
  File "C:\Python27\lib\zipfile.py", line 897, in open
    raise BadZipfile, "Bad magic number for file header"
zipfile.BadZipfile: Bad magic number for file header
Run Code Online (Sandbox Code Playgroud)

WinRAR可以提取我试图提取的文件.这是我用来从中提取文件的代码myzip.zip

from zipfile import ZipFile
z = ZipFile('myzip.zip')   //myzip.zip contains just one file, a password protected pdf        
for name in z.namelist():
    z.extract(name) …
Run Code Online (Sandbox Code Playgroud)

python unzip zipfile python-2.7

8
推荐指数
1
解决办法
2万
查看次数

用龙卷风web服务器运行你好世界的问题(Python 2.5,Win 7)

我在Windows 7(64位)上使用Python 2.5.

我安装了pycurl-7.15.5.1(带有win二进制文件)和龙卷风(使用pip).

当我运行以下hello world代码时:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello World!")

if __name__=='__main__':
    app = tornado.web.Application([(r"/",MainHandler),])
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误: -

Traceback (most recent call last):

  File "hello_tornado.py", line 11, in <module>
    application.listen(8888)
  File "c:\Python25\Lib\site-packages\tornado\web.py", line 1193, in listen
    server.listen(port, address)
  File "c:\Python25\Lib\site-packages\tornado\netutil.py", line 100, in listen
    sockets = bind_sockets(port, address=address)
  File "c:\Python25\Lib\site-packages\tornado\netutil.py", line 263, in bind_sockets
    sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
  AttributeError: 'module' object has no attribute 'IPV6_V6ONLY'
Run Code Online (Sandbox Code Playgroud)

python tornado ipv6

5
推荐指数
1
解决办法
2561
查看次数

cherrypy/dev/urandom(或等效)未找到 - 错误

我运行的CherryPy 3.2.0服务器与Python 2.5.1,它提供了以下错误每隔几天从UI任何指令,直至被杀害,并且重新开始: -

[29/Mar/2012:06:37:57] HTTP Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 636, in respond
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 97, in run
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 57, in __call__
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 757, in init
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 162, in __init__
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 190, in _regenerate
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 204, in generate_id
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cpcompat.py", line 264, in random20
File "/usr/lib/python2.5/os.py", line 733, in urandom
NotImplementedError: /dev/urandom (or equivalent) not found
Run Code Online (Sandbox Code Playgroud)

_cpcompat.py有一段代码表明,random.random如果cherrypy无法读取/dev/urandom,但似乎没有倒退,则会出现回落.

try:
    os.urandom(20)
    import …
Run Code Online (Sandbox Code Playgroud)

python random session cherrypy

5
推荐指数
1
解决办法
3085
查看次数

关于Vim正则表达式删除每行中的尾随空格

:%s/[ ]*$//g
Run Code Online (Sandbox Code Playgroud)

为什么上面的正则表达式在任何一行的末尾挤压> = 1个空格到正好一个但不是0个空格?

regex vim

3
推荐指数
1
解决办法
2053
查看次数

os.path.exists在Python CLI上无法正常工作

我的Windows 7机器上有Python 2.5.x.

os.path.exists('C:')              # returns True
os.path.exists('C:\Users')        # returns True
os.path.exists('C:\Users\alpha')  # returns False, when ALPHA is a user on my machine
Run Code Online (Sandbox Code Playgroud)

我给了我正在使用的CLI的读/写权限.可能的原因是什么?

python python-module

2
推荐指数
1
解决办法
1123
查看次数

如何禁用http访问我在GAE上运行的应用程序

我想禁用基于Web的访问我的应用程序给我或任何人.我有一些cron工作正在运行.这就是我想要的.

google-app-engine

2
推荐指数
1
解决办法
1353
查看次数

谷歌应用引擎发送邮件两次

我写了一个示例代码,用于从Python中的谷歌应用引擎发送电子邮件.我无法弄清楚为什么每次发送两次邮件?

mail.py: -

from google.appengine.api import mail

mail.send_mail(sender="ALPHA <ALPHA@gmail.com>",
        to="BETA <BETA@hotmail.com>",
        subject="test mail",
        body="""

Dear BETA,
How have you been?

Regards,
ALPHA
""")
Run Code Online (Sandbox Code Playgroud)

app.yaml: -

application: MyUniqueAppID
version: 1
runtime: python
api_version: 1

handlers:
- url: .*
script: mail.py
Run Code Online (Sandbox Code Playgroud)

python email google-app-engine

0
推荐指数
1
解决办法
530
查看次数