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
Related
I am trying to download a report I created on SalesForce using simple_salesforce package in python.
Below is the sample code:
from simple_salesforce import Salesforce
import requests
import pandas as pd
from io import StringIO
sf = Salesforce(username='myusername',
password='mypassword',
security_token='mytoken',
version='46.0')
report_id = 'myreportid'
sf.restful('analytics/reports/{}'.format(report_id))
However, this chunk of code yields the following error:
SalesforceExpiredSession: Expired session for https://company_name.my.salesforce.com/services/data/v46.0/analytics/reports/myreporid. Response content: [{'message': 'This session is not valid for use with the REST API', 'errorCode': 'INVALID_SESSION_ID'}]
(continuing from comments)
My bad, typo. Does your Profile have "API Enabled" checkbox ticked?
And you said you can see success in login history, active session?
What happens when you try to do same thing manually with workbench. Login, then in top menu Utilities -> REST Explorer should let you run your report.
Maybe simple is creating a SOAP session id which for whatever reason is incompatible with REST API (to be fair I thought they were pretty interchangeable, maybe your company disabled REST API, I heard it's possible to request that from SF support...)
If workbench works - you may have to login in simple different way, creating "connected app" and reading up about https://help.salesforce.com/s/articleView?id=remoteaccess_oauth_username_password_flow.htm&type=5&language=en_US for example
I have deployed a sas stored process as a web service . And I want to see the output of the stored process in python .
I would really appreciate if someone could help me for the same.
Here is the process I have used -
The webservice created was -
'https://sasdev.wdw.disney.com:443/SASBIWS/services/abcweb.wsdl'
I think, it stores the stored process in a function which here is abc_web()
The python code I am using here is -
import urllib
import logging
from suds.client import Client
#from suds.wsse import *
import requests
import suds_requests
url = 'https://sasdev.wdw.disney.com:443/SASBIWS/services/abcweb.wsdl'
namespace = 'https://sasdev.wdw.disney.com:443/SASBIWS/services'
client = Client(url)
client.service.abc_web()
But it receive an error as :
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://tempuri.org/abcweb" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:abc_web/>
</ns1:Body>
</SOAP-ENV:Envelope>
WebFault: Server raised fault: 'A 'Client Authentication' type of
exception occurred during execution of 'abcweb' service. The
exception follows: No security context is available.'
Error code 1000 means: Specifies an invalid user name or password (the client application might want to re-prompt the user for credentials). Source: http://support.sas.com/documentation/cdl/en/wbsvcdg/61496/HTML/default/viewer.htm#a003275627.htm
First of all, see if you can set up this WS in SoapUI with correct authentication.
See the image below. In SoapUI, click on your SOAP request, and then go to properties below where you will need to enter your domain\userid as well as password. SAS supports encryption, but on the assumption that it has Basic Authentication enabled, you could keep it plain text.
You should be able to run your SOAP request in SoapUI.
In effect, it will add to the standard SOAP envelop a HEAD tag with these lines below. You can see when you open SOAP Log in SOAP UI:
<soapenv:Header><wsse:Security soapenv:mustUnderstand="1"
xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd>
<wsse:UsernameToken wsu:Id="">
<wsse:Username>domain\username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"></wsse:Nonce>
<wsu:Created>2014-10-22T15:10:21.866Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>
Let me know here how you get on. I am sorry I can help you with Python direct, but if you get it to work in SoapUI, you can then compare SOAP requests between SoapIU and your Python client to see what Python does wrong.
P.S. If you don't like entering plain text passwords in SoapUI, you can use PROC PWENCODE to encrypt the password first and then copy paste it into SoapUI.
I succefully connected to SAS Web Services with auth using the script below:
Username and password need to be customized.
from cred import username, password
from suds.client import Client
from suds.wsse import *
security = Security()
token = UsernameToken(username, password)
security.tokens.append(token)
url = 'http://srv/SASBIWS/services/folder/add?WSDL'
client = Client(url = url)
client.set_options(wsse=security)
print client
params = client.factory.create('addParameters')
params.num1 = 32452352
params.num2 = 34
print params
print client.service.add(params)
Hope this helps as it resolve the issue of authentication to SASWebServices.
I am trying to access the mongolab REST api through python. Is the correct way to do this via pythons urllib2? I have tried the following:
import urllib2
p = urllib2.urlopen("https://api.mongolab.com/api/1/databases/mydb/collections/mycollection?apiKey=XXXXXXXXXXXXXXXX")
But this gives me an error:
urllib2.URLError: <urlopen error unknown url type: https>
What is the correct way of doing this? After connecting, how do I go on to POST a document to my collection? If someone could post up a code example, I would be very grateful. Thanks all for the help!
EDIT:
I've recompiled python with ssl support. How do I POST insert a document to a collection using mongolab REST API? Here is the code I have atm:
import urllib
import urllib2
url = "https://api.mongolab.com/api/1/databases/mydb/collections/mycollection?apiKey=XXXXXXXXXXXXXXXX"
data = {"x" : "1"}
request = urllib2.Request(url, data)
p = urllib2.urlopen(request)
Now, when I run this, I get the error
urllib2.HTTPError: HTTP Error 415: Unsupported Media Type
How do I insert documents using HTTP POST? Thanks!
That error is raised if you version of python does not include ssl support. What version are you using? Did you compile it yourself?
That said, when you get a version including ssl, using requests is a lot easier than urllib2, especially when POSTing data.
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 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