问题标签 [twisted.web]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1585 浏览

python - What's the difference between HttpClientFactory and Agent?

Before laying my question bare, some context is needed. I'm trying to issue HTTP GET and POST requests to a website, with the following caveats:

  • Redirects are expected
  • Cookies are required
  • Requests must pass through a SOCKS proxy (v4a)

Up until now, I've been using twisted.web.client.Agent and it's subclasses (e.g. BrowserLikeRedirectAgent), but unfortunately it seems as though SOCKS proxies are not supported yet (and ProxyAgent is a no-go because this class is for HTTP proxies).

I stumbled upon twisted-socks, which seems to allow me to do what I want, but I noticed that it uses HttpClientFactory instead of agent, hence my question: what is the difference between HttpClientFactory and Agent and when should I use each one?

Below is some example code using twisted-socks. I have two additional questions:

  1. How can I use cookies in this example? I tried passing a dict and a cookielib.CookieJar instance to HttpClientFactory's cookies kwarg, but this raises an error (something about a string being expected... how on earth do I send cookies as a string?)

  2. Can this code be refactored to use Agent? This would be ideal, as I already have a reasonably large codebase that is written with Agent in mind.

```

```

0 投票
2 回答
813 浏览

python - 如何在 Web 服务器上安装 twistedweb python 库

我有一个使用 TwistedWeb 用 python 编写的小应用程序。它是一个聊天服务器。现在一切都配置为 localhost。我想要的只是在服务器(Fatcow.com 提供的共享服务器)上运行这个 python 脚本。我的意思是脚本将一直工作,一些客户端将连接/断开它。Fatcow 给了我没有任何自定义库的 python 2.5。有没有办法和教程如何使它与 TwistedWeb 一起工作?

谢谢指教。

0 投票
3 回答
1551 浏览

python - 如何使用 twisted.web.client.Agent 及其子类编写代码测试?

我阅读了有关测试驱动开发的官方教程,但对我来说并没有太大帮助。我编写了一个小型库,它广泛使用了twisted.web.client.Agent它的子类(BrowserLikeRedirectAgent例如),但我一直在努力使教程的代码适应我自己的测试用例。

我看了看twisted.web.test.test_web,但我不明白如何使所有部分组合在一起。例如,根据官方教程,我仍然不知道如何从 中获取Protocol对象Agent

谁能告诉我如何为一些依赖于代理GETPOST数据的代码编写一个简单的测试?非常欢迎任何其他详细信息或建议...

非常感谢!

0 投票
0 回答
220 浏览

python - 我如何伪造一个 twisted.web.client.Response 对象用于测试目的?

我正在尝试为Protocol需要一个t.w.c.Response对象的 a 编写测试。我认为这就像使用适当的版本字符串、响应代码、短语和t.w.c.Header实例实例化对象一样简单,但我不确定如何处理最后一个参数_transport.

据我所知,响应主体在被调用_transport时将来自哪里。Response.deliverBody因为这正是我的协议必须能够处理的,所以似乎我也需要伪造 a _transport(假设我对该参数的作用的猜测是正确的)。

我的问题如下:

  1. 参数的目的是什么_transport?我的理解正确吗?
  2. 假设我的直觉是正确的,我怎么能伪造一个_transport我可以召唤deliverBody我的假人的东西Response
  3. 是否有更简单的方法来获取虚拟Response对象?

欢迎任何其他提示和建议!

0 投票
1 回答
244 浏览

python - 如何从`twisted.web._newclient.Response`实例获取远程IP

我有一个代码,它向网站发出请求(通过主机名请求,例如 - www.google.com)。远程主机发送响应。如何获取发送响应的主机的 IP?

附言

我正在使用扭曲的网络客户端

PS2

功能要求

0 投票
1 回答
186 浏览

python - 如何运行 Twisted Matrix Web 服务器

我想运行作为开源项目JInfinote一部分的演示。演示服务器是使用 Twisted Matrix 库/服务器编写的。但是我不知道如何运行它,如果它是我需要下载才能运行的独立服务器,还是它只是 python 或库以及如何配置整个东西。

当我尝试在 python 中运行它时,我得到了一些会话异常——就好像它试图逐个函数地执行代码函数一样。我将不胜感激。

我对这个问题的水平感到抱歉,但我不是 python 程序员,我只是想了解 JInfinote 项目,这是一个障碍。

0 投票
1 回答
1452 浏览

python - 扭曲错误:Request.write 在调用 Request.finish 后调用请求

我试图将慢速计算放入线程中,并收到错误“Request.write 在调用 Request.finish 后调用请求”。

我已经查看了答案,并找到了完全相同的问题,但该解决方案对我不起作用。请指教。

0 投票
1 回答
4082 浏览

python - 无法为 twisted.web 导入 python http 模块

我正在尝试执行一个使用twisted web 的python 程序,但由于某种原因它无法导入http。我对此很陌生,而且我对解决这个问题还不够熟悉。我已经做了一些谷歌搜索,但我真的找不到任何似乎与这个特定问题相关的东西,只有一些似乎无法解决问题的模糊相似的东西。

操作系统:CentOS 5.9 Python版本:2.7.5

这是导入的样子:

0 投票
1 回答
284 浏览

python - 旁遮普在 python 上安装扭曲运行错误

我正在尝试在 python 上安装旁遮普语,以便使用 openfire 和 stropher js 进行 bosh 设置工作。

当我尝试运行时twistd -y punjab.tac,我得到了以下错误。

我的 python 版本 2.7 我在几分钟前就安装了,但它一直在使用 pythin2.6 库。我对python没有更多的了解。

帮我..!!提前致谢 ...!!

0 投票
0 回答
89 浏览

python - Twisted Web 中对授权失败的自定义响应

我在使用 Python 的 Twisted 框架编写的 Web 服务器中使用 HTTP Digest Authentication。我想控制用户在身份验证对话框中按下取消时看到的页面,这应该是启动身份验证的 401 响应正文的文本。在 Apache 中,这可以使用 ErrorDocument 指令覆盖,在 Twisted 中我找不到更改 401 正文的方法。

我能找到的最简单的事情是将 的内容复制twisted.web._auth.wrapper.py到本地副本并重写UnauthorizedResource类以更改内容,然后使用MyHTTPAuthSessionWrapper创建更新资源的副本。这似乎有点“恶心”。还有比这更直接/更简单的方法吗?