twisted

FTP filename encoding

∥☆過路亽.° 提交于 2019-12-11 08:33:28
问题 Hi I use twisted library to connect to FTP server but I have problem with filename encoding. I receive 'Illusion-N\xf3z.txt' so its not unicode. Is there any FTP command to force specific encoding? Thanks in advance! MK 回答1: There are two possibilities: FTP is not unicode aware. It looks like the server you're talking to in this example is sending Latin-1 encoded bytes. So you need to decode the bytes using that encoding when you receive them. There is an RFC which updates FTP to be UTF-8

Services dependency and interaction in Twisted Python

点点圈 提交于 2019-12-11 07:52:04
问题 while working on Twisted, I was wondering if there is: a way to explicitly define services dependencies (e.g. in order to start service B, before I need to fire service A) a "pythonic" way to make two services communicate (e.g. B shares information with A, A can control B execution) Thanks 回答1: Take a look at Twisted Application Documentation. It sounds like you want to create a MultiService each with its own sub-Service implementation. What you do is define a number of services, implementing

Ajax POST doesnt work / Twisted

眉间皱痕 提交于 2019-12-11 07:29:49
问题 Twisted.Web and AJAX Similar thread already exits . I even took code from there , yet i have the same problem , the twisted server works like a charm, but can't figure out why i can't fetch it with ajax. In similar thread he says that alert comes out , but without data. For me even alert doesn't pop up , yet another ajax functions works , so in general with ajax is everything ok , but exactly with fetching something goes wrong. As also said in similar thread i can fetch it with curl - $ curl

How to catch unhandled error in Deferred originating from threads.deferToThread()

Deadly 提交于 2019-12-11 07:24:06
问题 I'm getting the error Unhandled error in Deferred: Can anybody help, how to handle this? @inlineCallbacks def start(self): # First we try Avahi, if it fails we fallback to Bluetooth because # the receiver may be able to use only one of them log.info("Trying to use this code with Avahi: %s", self.userdata) key_data = yield threads.deferToThread(self.discovery.find_key, self.userdata) if key_data and not self.stopped: success = True message = "" returnValue((key_data, success, message)) if self

twisted run local shell commands with pipeline

China☆狼群 提交于 2019-12-11 07:17:29
问题 In twisted, getProcessOutput method could get 'ps' shell command ouput by using getProcessOutupt('ps', 'aux') and return a defer. my question is how to run command like "ps aux | grep 'some keyword' | awk '{...}'" in getProcessOutput. for example getProcessOutput("ps aux | grep 'some keyword' | awk '{...}'") . any suggestions would be appreciated. 回答1: use getProcessOutput('/bin/sh', ('-c', cmd)) . cmd is your shell command. try it :-) 来源: https://stackoverflow.com/questions/28957258/twisted

Reconnect to different address in twisted?

99封情书 提交于 2019-12-11 07:07:09
问题 I have a server that sends my client the address of a backup server in case it goes down. On the server side the backup server is running. On the client side once the connection is lost I am not able to make the client to connect to the backup server. I know that I have to add the connection logic to the following callback in twisted.internet.protcol.Protocol class MyProtocol(Protocol): def connectionLost(self, reason): print 'Connection Lost' print 'Trying to reconnect' # How do I reconnect

How to get punjab/twisted to bypass dns

落花浮王杯 提交于 2019-12-11 06:48:08
问题 I am trying to get a punjab BOSH server to work with a development XMPP server. punjab is trying to do a SRV DNS lookup of the XMPP domain, which is not present in our DNS infrastructure. Is there any way I configure punjab to route requests for "myserver.mydomain.com" to an IP address? I do not have access to the xmpp:route attribute at the XML-level, so this would have to be done somehow by punjab/twisted configuration. 回答1: As a quick hack to get you up and running, install dnsmasq, add

How to make twisted defer get function result?

喜欢而已 提交于 2019-12-11 06:25:40
问题 I want to do something in multiprocessing , and I want to defer get result, something like this: from multiprocessing import Pool from twisted.internet import defer import time def f(x): time.sleep(0.5) print(x) return x*x pool = Pool(processes=4) # start 4 worker processes def get_result(i): res = pool.apply_async(f, (i, )) # do work in process pool return defer.Deferred(res.get()) # now, I want to make process do something else, so it should not be blocked def main(): from twisted.internet

Python/Twisted - How to print more detailed error message

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 06:15:22
问题 I run this code: import argparse from tqdm import tqdm from sys import argv from pprint import pformat from twisted.internet.task import react from twisted.web.client import Agent, readBody from twisted.web.http_headers import Headers from twisted.internet.task import cooperate from twisted.internet.defer import gatherResults import sys from twisted.python import log log.startLogging(sys.stdout) import lxml.html from geoip import geolite2 import pycountry from tld import get_tld import json

Python Memory usage doesnt drop

烂漫一生 提交于 2019-12-11 06:09:44
问题 I am writing a twisted PB application that seems to use a very large amount of memory that never seems to get released when the user disconnects. I have a pb.Root object that clients connect to and invoke a remote method that returns a pb.Referenceable object this object reads a large amount of information into memory (about 2GBs worth of data) when it is created to speed up the actions. This object, along with some other information about the client is inserted into a list. When the client