mechanize:饼干混淆了?
我正在使用 mechanize 从不同的代理访问同一网站。该网站有一个登录页面。我有 5 个代理和 5 个不同的登录名,每个代理使用一个登录名。
如果我只使用一个代理和一个登录来运行我的脚本,则每个脚本都可以正常工作。但是,如果我同时运行两个或多个代理/登录,那么我就会开始收到错误(来自网站),例如“您的会话已超时或未启用 cookie”。无论我是从同一脚本(同一进程)还是从不同脚本(不同进程)运行 5 个实例,都会发生这种情况。
什么会导致它单独工作而不是同时工作?
I'm using mechanize to visit the same web-site from different proxies. The website has a log-in page. I have 5 proxies and 5 different log-ins, one to use for each proxy.
If I just run my script with one proxy and one log-in, each one works fine. However, if I run two or more proxies/log-ins at once, then I start getting errors (from the website) like "either your session has timed out or cookies are not enabled." This happens whether I'm running the 5 instances from the same script (same process), or from different scripts (different processes).
What would cause this to work individually but not all at once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为 mechanize 默认情况下会自动创建一个共享的“cookie jar”。对于更高级的 cookie 处理选项,您必须为每个脚本会话创建自己的 cookie jar。
我必须在过去的项目中使用自定义 cookie 罐,以便将 cookie 从一个会话移动到另一个会话。最终结果是相同的,脚本的每个实例都有自己唯一的文件来存储 cookie,因此您需要管理 cookie 文件并确保它们不会混淆。
在我测试的这个示例中,您可以看到两个 mechanize 对象,每个对象都有自己独立的 cookie jar。
That is because mechanize automatically creates a shared "cookie jar" by default. For more advanced cookie handling options, you will have to create your own cookie jar for each of the script sessions.
I had to use a custom cookie jar in a past project, in order to move cookies from one session to another. The end result is the same, each instance of your script would have it's own unique file to store it's cookies, so it's on you to manage the cookie files and know that they don't get confused.
In this example I've tested, you can see the two mechanize objects, each with it's own independent cookie jar.