如何从使用 OpenID 的网站请求页面?
这个问题之前已经在这里提出过。接受的答案对于提问者和回答者来说可能都是显而易见的——但对我来说却不然。我对上述问题进行了评论以获取更精确的信息,但没有得到回应。 我还访问了元问答以获取有关如何带回问题的帮助从他们的坟墓里出来,也没有得到答案。
上述问题的答案是:
从客户端的角度来看,OpenID 登录与任何其他基于 Web 的登录非常相似。没有为客户端定义的协议;这是一个普通的 Web 会话,根据您的 OpenID 提供商的不同而有所不同。因此,我怀疑是否存在这样的库。您可能需要自己编写代码。
我知道如何使用 Python 登录网站已经使用 Urllib2 模块。但这还不足以让我猜测如何验证 OpenID。
我实际上正在尝试获取 我的 json 格式的 StackOverflow 收件箱,为此我需要登录。
有人可以提供一个简短的信息吗?介绍或关于如何做到这一点的好教程的链接?
This question has been asked here before. The accepted answer was probably obvious to both questioner and answerer---but not to me. I have commented on the above question to get more precisions, but there was no response. I also approached the meta Q&A for help on how to bring back questions from their grave, and got no answer either.
The answer to the here above question was:
From the client's perspective, an OpenID login is very similar to any other web-based login. There isn't a defined protocol for the client; it is an ordinary web session that varies based on your OpenID provider. For this reason, I doubt that any such libraries exist. You will probably have to code it yourself.
I know how to log onto a website with Python already, using the Urllib2 module. But that's not enough for me to guess how to authenticate to an OpenID.
I'm actually trying to get my StackOverflow inbox in json format, for which I need to be logged in.
Could someone provide a short intro or a link to a nice tutorial on how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我自己对 OpenID 不太了解,但你的帖子(和赏金!!)让我感兴趣。
此链接说明了 OpenID 身份验证序列的确切流程(至少适用于 v1.0。新版本是2.0)。据我所知,这些步骤类似于“
此链接介绍了 OpenID 中的各种响应及其含义。因此,当您为客户编写代码时,它可能会派上用场。
来自 wiki 页面的链接 OpenID 解释
编辑:使用 Firefox 的 Tamper Data Add on,可以执行以下事件序列建造的。
重定向 URL 有很多 OpenID 参数(用于 google 服务器)。其中之一是 return_to=https://stackoverflow.com/users/authenticate/?s=some_value。
我建议你开始编写你的 python 客户端并仔细研究响应。在大多数情况下,这将是一系列 302,用户干预最少(除了填写您的 Google 用户名和密码并允许访问网站页面)。
然而,为了更简单,您可以使用浏览器登录 SO,复制所有 cookie 值,并使用设置了 cookie 值的 urllib2 发出请求。
当然,如果您在浏览器上注销,则必须重新登录并更改 python 程序中的 cookie 值。
Well I myself don't know much about OpenID but your post (and the bounty!!) got me interested.
This link tells the exact flow of OpenID authentication sequence (Atleast for v1.0. The new version is 2.0). From what I could make out, the steps would be something like
This link tells about various responses in OpenID and what they mean. So maybe it will come in handy when your code your client.
Links from the wiki page OpenID Explained
EDIT: Using Tamper Data Add on for Firefox, the following sequence of events can be constructed.
The redirect URL has a lot of OpenID parameters (which are for the google server). One of them is return_to=https://stackoverflow.com/users/authenticate/?s=some_value.
I suggest you start coding your python client and study the responses carefully. In most cases it will be a series of 302's with minimal user intervention (except for filling out your Google username and password and allowing the site page).
However to make it easier, you could just login to SO using your browser, copy all the cookie values and make a request using urllib2 with the cookie values set.
Of course in case you log out on the browser, you will have to login again and change the cookie value in your python program.
我知道这接近考古学,挖掘一篇两年前的帖子,但我刚刚根据经过验证的答案编写了代码的新增强版本,所以我认为在这里分享它可能很酷,因为这个问题/答案已经对我实现这一点有很大帮助。
因此,以下是不同之处:
requests
库,该库是对urllib2
的增强;这是代码:
该代码也可以作为 github gist
华泰
I know this is close to archeology, digging a post that's two years old, but I just wrote a new enhanced version of the code from the validated answer, so I thought it may be cool to share it here, as this question/answers has been a great help for me to implement that.
So, here's what's different:
requests
library that is an enhancement overurllib2
;here's the code:
the code is also available as a github gist
HTH
这个答案总结了其他人在下面所说的内容,特别是 RedBaron,并添加了我用来访问的方法使用 Google 帐户的 StackOverflow Inbox。
使用 Firefox 的 Tamper Data 开发者工具并登录 StackOVerflow,可以看到 OpenID 的工作方式如下:
上面总结了这个过程,实际上更复杂,因为确实发生了许多重定向和 cookie 交换。
因为以编程方式复制相同的过程被证明有些困难(这可能只是我的文盲),特别是试图寻找要调用的所有区域设置细节等的 URL。我选择首先登录 Google 帐户,获得一个当之无愧的 cookie 并然后登录 Stackoverflow,它将使用 cookie 进行身份验证。
只需使用以下 Python 模块即可完成此操作:urllib、urllib2、cookielib 和 BeautifulSoup。
这是(简化的)代码,它并不完美,但它可以解决问题。扩展版本可以在 Github 上找到。
This answer sums up what others have said below, especially RedBaron, plus adding a method I used to get to the StackOverflow Inbox using Google Accounts.
Using the Tamper Data developer tool of Firefox and logging on to StackOVerflow, one can see that OpenID works this way:
The above sums up the process, which in reality is more complicated, since many redirects and cookie exchanges occur indeed.
Because reproducing the same process programmatically proved somehow difficult (and that might just be my illiteracy), especially trying to hunt down the URLs to call with all locale specifics etc. I opted for loging on to Google Accounts first, getting a well deserved cookie and then login onto Stackoverflow, which would use the cookie for authentication.
This is done simply using the following Python modules: urllib, urllib2, cookielib and BeautifulSoup.
Here is the (simplified) code, it's not perfect, but it does the trick. The extended version can be found on Github.
您需要在任何“登录”页面上实现cookie,在Python中您使用 cookiejar。例如:
You need to implement cookies on any "login" page, in Python you use cookiejar. For example:
我制作了一个使用 Mozilla Firefox cookie 登录 stackoverflow.com 的简单脚本。它不是完全自动化的,因为你需要手动登录,但这就是我设法做的。
Scipt适用于最新版本的FF(我使用的是8.0.1),但是你需要获取最新的sqlite dll,因为python 2.7附带的默认版本无法打开DB。您可以在这里获取它: http://www.sqlite.org/sqlite -dll-win32-x86-3070900.zip
I made a simple script that logins to stackoverflow.com using Mozilla Firefox cookies. It's not entirely automated, because you need to login manually, but it's all i managed to do.
Scipt is actual for latest versions of FF ( i'm using 8.0.1 ), but you need to get latest sqlite dll, because default one that comes with python 2.7 can't open DB. You can get it here: http://www.sqlite.org/sqlite-dll-win32-x86-3070900.zip