小编sen*_*nte的帖子

如何使用ftp(/ usr/bin/ftp)匿名登录?

我正在尝试连接到允许匿名访问的FTP服务器,但我不知道如何指定执行此操作所需的相应用户名/密码.

我尝试使用匿名/匿名作为用户/传递没有运气,以及空字符串和两者的各种组合等.

它必须是我想念的简单东西,我可以使用连接 curl ftp://server/

使用python:

stu@sente ~ $ cat - | python
import ftplib
ftp = ftplib.FTP("ftp.server")
ftp.set_debuglevel(2)
ftp.connect()
ftp.login()
list = ftp.nlst()
ftp.close()
print "\n", " ".join(list)
^D

*get* '220 ftp.server NcFTPd Server (licensed copy) ready.\r\n'
*resp* '220 ftp.server NcFTPd Server (licensed copy) ready.'
*cmd* 'USER anonymous'
*put* 'USER anonymous\r\n'
*get* '331 Guest login ok, send your complete e-mail address as password.\r\n'
*resp* '331 Guest login ok, send your complete e-mail address as password.'
*cmd* 'PASS **********'
*put* …
Run Code Online (Sandbox Code Playgroud)

ftp

20
推荐指数
2
解决办法
14万
查看次数

为什么lxml.etree.iterparse()占用了我所有的记忆?

这最终消耗了我所有可用的内存,然后该进程被终止.我已经尝试将标签更改schedule为"较小"标签,但这并没有什么区别.

我做错了什么/如何处理这个大文件iterparse()

import lxml.etree

for schedule in lxml.etree.iterparse('really-big-file.xml', tag='schedule'):
    print "why does this consume all my memory?"
Run Code Online (Sandbox Code Playgroud)

我可以轻松地将其切割并以较小的块处理它,但这比我想要的更糟糕.

python xml memory lxml iterparse

19
推荐指数
2
解决办法
8580
查看次数

为什么urllib.urlopen(url)在urllib2.urlopen(url)工作时失败.具体关于服务器响应的原因是什么?

我只是想更好地了解这里发生了什么,我当然可以通过使用urllib2"解决"这个问题.

import urllib
import urllib2

url = "http://www.crutchfield.com/S-pqvJFyfA8KG/p_15410415/Dynamat-10415-Xtreme-Speaker-Kit.html"

# urllib2 works fine (foo.headers / foo.read() also behave)
foo = urllib2.urlopen(url)

# urllib throws errors though, what specifically is causing this?
bar = urllib.urlopen(url)
Run Code Online (Sandbox Code Playgroud)

http://pae.st/AxDW/使用异常/ stacktrace显示此代码. foo.headersfoo.read()做工精细

stu@sente.cc~ $:curl -I "http://www.crutchfield.com/S-pqvJFyfA8KG/p_15410415/Dynamat-10415-Xtreme-Speaker-Kit.html"

HTTP/1.1 302 Object Moved
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Location: /S-FSTWJcduy5w/p_15410415/Dynamat-10415-Xtreme-Speaker-Kit.html
Server: Microsoft-IIS/7.5
Set-Cookie: SESSIONID=FSTWJcduy5w; domain=.crutchfield.com; expires=Fri, 22-Feb-2013 22:06:43 GMT; path=/
Set-Cookie: SYSTEMID=0; domain=.crutchfield.com; expires=Fri, 22-Feb-2013 22:06:43 GMT; path=/
Set-Cookie: SESSIONDATE=02/23/2012 17:07:00; …
Run Code Online (Sandbox Code Playgroud)

python http urllib urllib2

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

如何记录IPython的输出,而不是在每次加载时都有丑陋的7行logging-info?

我的目标是调用ipython,同时还将所有输入/输出记录到IPython,并看到如下内容:

stu@stumac ~  $ ipython

In [1]: exit
stu@stumac ~  $
Run Code Online (Sandbox Code Playgroud)

如果我设置,可以轻松删除横幅

c.TerminalIPythonApp.display_banner = False

在我的 ~/.ipython/profile-default/ipython_config.py档案中.

但是,如何在记录事物的同时获得初创公司的清洁?

在全新安装中,如果我在没有参数的情况下启动IPython,我会看到:

sente@og ~ $ ipython
Python 2.7.3 (default, Jun 20 2013, 12:50:58)
Type "copyright", "credits" or "license" for more information.

IPython 0.13.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: exit
sente@og …
Run Code Online (Sandbox Code Playgroud)

python installation logging ipython dotfiles

7
推荐指数
1
解决办法
1541
查看次数

如何配置IPython 5以获得IPython 3的readline,tab-completion,(缺少)语法高亮等?(self.IPython)

我知道在某些时候我可能想要"升级",但是现在我只想要旧的外观和感觉.

我知道IPython是非常可配置的,但我没有太多运气找到正确的设置.

(顺便提一句,这只涉及IPython的交互式终端)

python configuration ipython

6
推荐指数
1
解决办法
222
查看次数

如何逐步使用 python 调试器在每次函数调用时中断?

我想密切监视从某个函数调用的函数调用链。

import pdb; pdb.set_trace()
res = api.InsertVideoEntry(video_entry, video)
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种方法来轻松查看api.insertVideoEntry(video_entry, video)调用foo()which call bar()which calls 的调用baz()

这是一个非常粗糙的图表来说明我的意思。我不需要这种形式的信息,但这是我正在寻找的那种信息。

api.insertVideoEntry()
    foo()
        bar()
            baz()
            baz2()
        log()
    finish()
Run Code Online (Sandbox Code Playgroud)

python debugging pdb

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

Python - 有一种优雅的方法可以避免数十个try/except块从json对象中获取数据吗?

我正在寻找编写函数的方法,get_profile(js)但没有所有丑陋的尝试/例外.

每个赋值都在try/except中,因为偶尔json字段不存在.我会很高兴有一个优雅的解决方案,None即使我设置了一些默认设置[],但是如果这样做会使整个代码更好,那么默认一切都是如此.

def get_profile(js):
    """ given a json object, return a dict of a subset of the data.
        what are some cleaner/terser ways to implement this?

        There will be many other get_foo(js), get_bar(js) functions which
        need to do the same general type of thing.
    """

    d = {}

    try:
        d['links'] = js['entry']['gd$feedLink']
    except:
        d['links'] = []

    try:
        d['statisitcs'] = js['entry']['yt$statistics']
    except:
        d['statistics'] = {}

    try:
        d['published'] = js['entry']['published']['$t']
    except:
        d['published'] = ''

    try:
        d['updated'] …
Run Code Online (Sandbox Code Playgroud)

python json

3
推荐指数
2
解决办法
866
查看次数

nginx - 可以配置代理缓存,以便在没有HTTP标头的情况下保存文件,或者以更"人性化"的格式保存文件吗?

我很好奇是否可以配置nginx以便以某种方式保存缓存,使数据用户友好?虽然我的所有选择都可能达不到任何人会认为"人性化"的东西,但我一般都对人们如何配置它以满足他们的特定需求感兴趣.文档可能是完整的,但我非常熟悉示例类型的人.

我当前的配置来自我运行的一个例子,如果它被使用woud并不是证明nginx正确代理缓存/数据

http {    

# unrelated stuff...

proxy_cache_path  /var/www/cache levels=1:2 keys_zone=my-cache:8m max_size=1000m inactive=600m;
proxy_temp_path /var/www/cache/tmp; 

server {
    server_name g.sente.cc;
    location /stu/ {
    proxy_pass http://sente.cc;
    proxy_cache my-cache;
    proxy_cache_valid  200 302  60m;
    proxy_cache_valid  404      1m;
    }
}
Run Code Online (Sandbox Code Playgroud)

proxy caching nginx

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

我想在类中修饰一个方法但不编辑class.py - 里面的细节

Twython模块在内部使用请求模块.

我想包装/装饰请求的requests.post(*k, **kw)方法,所以Twython进行request.post(...)调用它将被透明地装饰/包裹,而不会干扰Twython模块.

如果我编辑了请求代码库,这很容易,但我很好奇如何解决向已定义的函数/方法添加装饰器的一般问题.

import requests
def magic_wrapper_doodad(...)
...
...
requests.post = magic_wrapper_doodad(my_function, requests.post) # plz?

import Twython

# thanks to the above magic, requests.post is wrapped just as if it was defined like:
@decorator
def trace(f, *args, **kw):
    print("calling %s with args %s, %s" % (f.__name__, args, kw))
    return f(*args, **kw)

...
... #inside requests.py now:
@trace
def post(self, *args, **kw):
...
Run Code Online (Sandbox Code Playgroud)

我该怎么写magic_wrapper_doodad()- 或者一些替代代码 - 所以我可以像这样装饰代码?

python class decorator wrapper python-decorators

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