I am using the following python code to display all methods offered by a webservice generated from a wsdl version 2.0 file.
The url is the following:
http://localhost:8080/axis2/services/UserService?wsdl2
Using the above url, the browser displays the wsdl file but when using this url in a python application below, it returns only the following info and nothing related to the webservice methods in question.
Python code
from suds.wsse import *
from suds.client import Client
myclient = Client("http://localhost:8080/axis2/services/UserService?wsdl2")
print myclient
output
Suds ( https://fedorahosted.org/suds/ ) version: 0.3.9 GA build: R659-20100219
it should be returing the methods available in the webservice as in the example https://fedorahosted.org/suds/wiki/Documentation
any idea?
Try removing the /tmp/suds directory. Also try passing cache=None in the Client constructor:
myclient = Client("http://localhost:8080/axis2/services/UserService?wsdl2", cache=None)
It seems that still suds doesn't support WSDL 2.
See https://fedorahosted.org/suds/ticket/479
Related
I want to consume data from WSDL url, I don't know how would I do in python.
Can anyone help me with the example
here is the WSDL link for reference :
http://43.242.214.173/cwplservice/cwplonline.svc?wsdl
Here is code snippet which I have tried.
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
url = 'http://43.242.214.173/cwplservice/cwplonline.svc?wsdl'
imp = Import('http://212.235.42.50/WebService/service.php?class=masterPricer', location='https://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://www.w3.org/2001/XMLSchema')
client = Client(url, doctor=ImportDoctor(imp))
print client
when I run the code I am getting following error as
suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'
Did you looked into PySimpleSOAP? I've used it, it is pretty good for making SOAP calls and parsing small size XML responses. For very large XML message responses it has crashed on me, ended up writing my own XML handler using xml.etree.ElemenTree.
https://pypi.python.org/pypi/PySimpleSOAP/1.02b
Environment : CentOS 6.4 64bit, Python 2.6.6, Magento 1.7, Magento Core API, Suds 0.4.1
Python Code:
client = Client(http:// /figol/api/soap/?wsdl)
client.service.login('figol', 'figol123')
Error Detail:
TypeNotFound: Type not found: '(Array, http://schemas.xmlsoap.org/soap/encoding/, )
But
PHP Code:
$client = new SoapClient(http:// /figol/api/soap/?wsdl);
$session = $client->login('figol', 'figol123');
Works Perfectly.
I have tried many way(SOAP suds and the dreaded schema Type Not Found error), but there is no luck.
Any help is very appreciated.
Thanks.
Don't know how PHP works fine but I've encounter the same error when use suds in Python. This is due to broken wsdl/xsd. See this post here.
Using suds's 'doctor' module solves this issue. Here is my code used to patch the broken wsdl definition I used to connect Magento api
from suds.client import Client
from suds.xsd.doctor import ImportDoctor, Import
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add('urn:Magento')
d = ImportDoctor(imp)
client = Client(self.url, doctor=d)
I'm new to Python, new to the jira-python library, and new to network programming, though I do have quite a bit of experience with application and integration programming and database queries (though it's been a while).
Using Python 2.7 and requests 1.0.3
I'm trying to use this library - http://jira-python.readthedocs.org/en/latest/ to query Jira 5.1 using Python. I successfully connected using an unauthenticated query, though I had to make a change to a line in client.py, changing
I changed
self._session = requests.session(verify=verify, hooks={'args': self._add_content_type})
to
self._session = requests.session()
I didn't know what I was doing exactly but before the change I got an error and after the change I got a successful list of project names returned.
Then I tried basic authentication so I can take advantage of my Jira permissions and do reporting. That failed initially too. And I made the same change to
def _create_http_basic_session
in client.py , but now I just get another error. So problem not solved. Now I get a different error:
HTTP Status 415 - Unsupported Media Type
type Status report
message Unsupported Media Type
description The server refused this request because the request entity is in
a format not` `supported by the requested resource for the requested method
(Unsupported Media Type).
So then I decided to do a super simple test just using the requests module, which I believe is being used by the jira-python module and this code seemed to log me in. I got a good response:
import requests
r = requests.get(the_url, auth=(my username , password))
print r.text
Any suggestions?
Here's how I use the jira module with authentication in a Python script:
from jira.client import JIRA
import logging
# Defines a function for connecting to Jira
def connect_jira(log, jira_server, jira_user, jira_password):
'''
Connect to JIRA. Return None on error
'''
try:
log.info("Connecting to JIRA: %s" % jira_server)
jira_options = {'server': jira_server}
jira = JIRA(options=jira_options, basic_auth=(jira_user, jira_password))
# ^--- Note the tuple
return jira
except Exception,e:
log.error("Failed to connect to JIRA: %s" % e)
return None
# create logger
log = logging.getLogger(__name__)
# NOTE: You put your login details in the function call connect_jira(..) below!
# create a connection object, jc
jc = connect_jira(log, "https://myjira.mydom.com", "myusername", "mypassword")
# print names of all projects
projects = jc.projects()
for v in projects:
print v
Below Python script connects to Jira and does basic authentication and lists all projects.
from jira.client import JIRA
options = {'server': 'Jira-URL'}
jira = JIRA(options, basic_auth=('username', 'password'))
projects = jira.projects()
for v in projects:
print v
It prints a list of all the project's available within your instance of Jira.
Problem:
As of June 2019, Atlassian Cloud users who are using a REST endpoint in Jira or Confluence Cloud with basic or cookie-based authentication will need to update their app or integration processes to use an API token, OAuth, or Atlassian Connect.
After June 5th, 2019 attempts to authenticate via basic auth with an Atlassian account password will return an invalid credentials error.
Reference: Deprecation of basic authentication with passwords for Jira and Confluence APIs
Solution to the Above-mentioned Problem:
You can use an API token to authenticate a script or other process with an Atlassian cloud product. You generate the token from your Atlassian account, then copy and paste it to the script.
If you use two-step verification to authenticate, your script will need to use a REST API token to authenticate.
Steps to Create an API Token from your Atlassian Account:
Log in to https://id.atlassian.com/manage/api-tokens
Click Create API token.
From the dialog that appears, enter a memorable and concise Label for your token and click Create.
Click Copy to clipboard, then paste the token to your script.
Reference: API tokens
Python 3.8 Code Reference
from jira.client import JIRA
jira_client = JIRA(options={'server': JIRA_URL}, basic_auth=(JIRA_USERNAME, JIRA_TOKEN))
issue = jira_client.issue('PLAT-8742')
print(issue.fields.summary)
Don't change the library, instead put your credentials inside the ~/.netrc file.
If you put them there you will also be able to test your calls using curl or wget.
I am not sure anymore about compatibility with Jira 5.x, only 7.x and 6.4 are currently tested. If you setup an instance for testing I could modify the integration tests to run against it, too.
My lucky guess is that you broke it with that change.
As of 2019 Atlassian has deprecated authorizing with passwords.
You can easily replace the password with an API Token created here.
Here's a minimalistic example:
pip install jira
from jira import JIRA
jira = JIRA("YOUR-JIRA-URL", basic_auth=("YOUR-EMAIL", "YOUR-API-TOKEN"))
issue = jira.issue("YOUR-ISSUE-KEY (e.g. ABC-13)")
print(issue.fields.summary)
I recommend storing your API Token as an environment variable and accessing it with os.environ[key].
im trying to build an client for an webservice in python with suds. i used the tutorial
on this site: http://www.jansipke.nl/python-soap-client-with-suds. Its working with my own written Webservice and WSDL, but not with the wsdl file i got. The wsdl file is working in soapUI, i can send requests and get an answer. So the problem is, i think, how suds is parsing the wsdl file. I get following error:
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>
Any ideas how to fix that? If you need more information please ask. Thank you!
The error you have given us seems to imply that the URL you are using to access the WSDL is not correct. could you show us a bit more of your code? for example the client instatiation and the url to the WSDL. this might allow others to actually help you.
Olly
# SUDS is primarily built for Python 2.6/7 (Lightweight SOAP client)
# SUDS does not work properly with other version, absolutely no support for 3.x
# Test your code with Python 2.7.12 (I am using)
from suds.client import Client
from suds.sax.text import Raw
# Use your tested URL same format with '?wsdl', Check once in SOAP-UI, below is dummy
# Make sure to use same Method name in below function 'client.service.MethodName'
url = 'http://localhost:8080/your/path/MethodName?wsdl'
#Use your Request XML, below is dummy, format xml=Raw('xml_text')
xml = Raw('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:diag=" </soapenv:Body></soapenv:Envelope>')
def GetResCode(url, xml):
client = Client(url)
xml_response = (client.service.MethodName(__inject={'msg':xml}))
return xml_response
print(GetResCode(url,xml))
I'm using Python's SUDs lib to access Sharepoint web services.
I followed the standard doc from Suds's website.
For the past 2 days, no matter which service I access, the remote service always returns 403 Forbidden.
I'm using Suds 0.4 so it has built-in support for accessing Python NTLM.
Let me know if anyone has a clue about this.
from suds import transport
from suds import client
from suds.transport.https import WindowsHttpAuthenticated
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
ntlm = WindowsHttpAuthenticated(username='USER_ID', password='PASS')
c_lists = client.Client(url='https://SHAREPOINT_URL/_vti_bin/Lists.asmx?WSDL', transport=ntlm)
#c_lists = client.Client(url='https://SHAREPOINT_URL/_vti_bin/spsearch.asmx?WSDL')
#print c_lists
listsCollection = c_lists.service.GetListCollection()
Are you specifying the username as DOMAIN\USER_ID as indicated in examples for the python-ntlm library? (Also see this answer).