使用python

时间:2017-07-17 13:08:26

标签: python single-sign-on

我需要在Python中发布和验证SSO站点。我尝试使用:

#!/usr/bin/python
import json
import urllib2
import requests
import urlparse

Class SSO

 ##########################
class SSOSite(requests.Session):
    def __init__(self,baseurl,login_page='/'):
        super(SSOSite,self).__init__()
        self.baseurl=baseurl
        self.login_url=urlparse.urljoin(baseurl,login_page)

    def login(self,username,password):
        # Fix this, assumes all sites take 'email' and 'password' as params.
        payload={'email':username,'password':password}
        return self.post(self.login_url,data=payload)

定义行动

if __name__=='__main__':
    #create any number of SSOSite objects
    s=SSOSite('https://example.com')
    print s.login('myuser', 'mypassword')
    # <Response [200]>
    print s.get('https://example.com/incident.do?JSON&sysparm_action=insert')
    # <Response [200]>
    url = 'https://example.com/incident.do?JSON&sysparm_action=insert'

发送JSON内容

headers = {'content-type': 'application/json'}
content = {"short_description": "ALERTA DE VULNERABILIDADE", "priority": "1", "description": "O Servidor esta fora"}

#s = requests.get(url, data=json.dumps(content), headers=headers)
s = requests.post(url, data=json.dumps(content), headers=headers)
s.raise_for_status()
print s

回复是<Response [200]>,但不是。我做错了什么?

0 个答案:

没有答案