在经过身份验证的会话中使用 twill/mechanize 检索 application/json 文档

发布于 2024-09-24 14:56:08 字数 297 浏览 0 评论 0原文

我需要检索 MIME 类型为“application/json”的文档。我正在使用 twill 登录网站,当我尝试转到指向 JSON 文档的 URL 并显示它时,我收到以下消息:

'The HTTP header field "Accept" with value "text/html; */*" could not be parsed.'

我有尝试将“Accept”字段更改为“application/json”,但仍然没有骰子。

谢谢!!

I need to retrieve a document with MIME type "application/json". I'm using twill to log in to a site and when I attempt to go to the URL pointing to the JSON document and show it, I get this message:

'The HTTP header field "Accept" with value "text/html; */*" could not be parsed.'

I have tried changing the "Accept" field to "application/json" but still no dice.

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

熊抱啵儿 2024-10-01 14:56:08

这绝不是我正在寻找的答案,但 zope.testbrowser 可以我想要什么。

界面比斜纹稍微复杂一些,但也不是很多。

仍在寻找斜纹布解决方案!

This is by no means the answer I'm looking for, but zope.testbrowser will do what I want.

The interface is slightly more complicated than twill, but not by much.

Still looking for a twill solution!

挖个坑埋了你 2024-10-01 14:56:08

看起来你有 Accept: text/html; */* 对我来说似乎语法错误:根据 w3.org< /a>,语法为

    <field>  =    Accept: <entry> *[ , <entry> ]
    <entry>  =    <content type> *[ ; <param> ]
    <param>  =    <attr> = <float>
    <attr>   =    q / mxs / mxb
    <float>  =    <ANSI-C floating point text represntation>

*/*,因为它后面是分号而不是逗号,应该 >,但实际上不是 的形式= <浮动>。您是否想在分号后面添加一个 q=something,,却忘了给出它?否则,只是 text/html, */* ——即用逗号,而不是分号——似乎是正确的语法。

Looks like you have Accept: text/html; */* which seems syntactically wrong to me: per w3.org, the syntax is

    <field>  =    Accept: <entry> *[ , <entry> ]
    <entry>  =    <content type> *[ ; <param> ]
    <param>  =    <attr> = <float>
    <attr>   =    q / mxs / mxb
    <float>  =    <ANSI-C floating point text represntation>

so that */*, since it follows a semicolon rather than a comma, should be a <param>, but not in fact of the form <attr> = <float>. Did you mean to have a q=something, after the semicolon, and forgot to give it? Else, just text/html, */* -- i.e., with a comma, not a semicolon -- seems to be the right syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文