How to fix an 'Invalid tag name' in WSDL request using Zeep? - wsdl

When trying to access a WSDL service, I get the following error:
ValueError: Invalid tag name 'Foo\\Bar\\Baz\\Etc\\V3Port'
The port which is provided through the WSDL-link actually has single backslashes: 'Foo\Bar\Baz\Etc\V3Port'
The ValueError gets raised when zeep calls the apihelpers.pxi method in the lxml library.
Any idea how I can fix this?
(BTW: the script worked fine when I used it 2 months ago. The WSDL-link hasn't changed)

I have found a solution
Before, it was sufficient to do:
from zeep import Client
Now, apparently, I need to explicitly add:
from lxml import etree
Everything works as before now.

Zeep does not like like "/" in values also. It gives invalid tag name error any time it finds any character in value that it does not like. For all such errors, you need to modify as_qname function in utils.py located in root folder of zeep library.
In my case, it was complaining for "/" in value, which is a valid value. I had to add below line to as_qname function.
value = value.replace("/", "-")
Below are first few lines of as_qname after modification
def as_qname(value: str, nsmap, target_namespace=None) -> etree.QName:
"""Convert the given value to a QName"""
value = value.strip() # some xsd's contain leading/trailing spaces
value = value.replace("/", "-") # Added by me.
if ":" in value:
prefix, local = value.split(":")

Related

Am I using TextLoader wrong when running the ML.Net Iris demo in F#?

I am new to F#/.NET and I am trying to run the F# example provided in the accepted answer of How to translate the intro ML.Net demo to F#? with the ML.NET library, using F# on Visual Studio, using Microsoft.ML (0.2.0).
When building it I get the error error FS0039: The type 'TextLoader' is not defined.
To avoid this, I added the line
open Microsoft.ML.Data
to the source.
Then, however, the line
pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ","))
triggers:
error FS0033: The non-generic type 'Microsoft.ML.Data.TextLoader' does not expect any type arguments, but here is given 1 type argument(s)
Changing to:
pipeline.Add(new TextLoader(dataPath,separator = ","))
yields:
error FS0495: The object constructor 'TextLoader' has no argument or settable return property 'separator'. The required signature is TextLoader(filePath: string) : TextLoader.
Changing to:
pipeline.Add(new TextLoader(dataPath))
makes the build successful, but the code fails when running with
ArgumentOutOfRangeException: Column #1 not found in the dataset (it only has 1 columns), I assume because the comma separator is not correctly picked up (incidentally, you can find and inspect the iris dataset at https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data).
Also
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
won't work.
I understand that there have been changes in TextLoader recently (see e.g. https://github.com/dotnet/machinelearning/issues/332), can somebody point me to what I am doing wrong?
F# just has a bit of a different syntax that can take some getting used to. It doesn't use the new keyword to instantiate a new class and to use named parameters it uses the = instead of : that you would in C#.
So for this line in C#:
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
It would be this in F#:
pipeline.Add(TextLoader(dataPath).CreateFrom<IrisData>(separator=','))

Drupal 8 issue: InvalidArgumentException: The URI '' is invalid

I am struggling with this issue:
InvalidArgumentException: The URI '' is invalid.
You must use a valid URI scheme. in Drupal\Core\Url::fromUri()
(line 284 of core/lib/Drupal/Core/Url.php).
How can I fix this?
You are passing a blank uri into the method. It is complaining about missing a scheme (eg. http:// or https://, or an internal scheme eg: internal:/)
So either you are explicitly passing a blank, or something isn't being set correctly. However, it does not seem to be null.
I had similar issue in Drupal 8 site, please make sure your files directory path is set correctly
I my case files path was Private and it was not configured in settings.php.
$settings['file_private_path'] = 'sites/default/files/private';
From the looks of the source code for the fromUri() function it would appear as though it throws that error when the PHP parse_url function returns an empty scheme:
... elseif (empty($uri_parts['scheme'])) { throw new \InvalidArgumentException("The URI '$uri' is invalid. You must use a valid URI scheme."); ...
From what I can gather in your question you seem to be providing an empty/null value to the fromUri method which is in turn causing the script to error when it attempts to parse the value. So I'd imagine that you'd need to do some kind of check before passing it to the fromUri function.
An example of how to use this method is helpfully provided in the comments section of the fromUri page: https://api.drupal.org/comment/61905#comment-61905
In case your URI is public://, then use:
\Drupal::service('file_url_generator')->generate($file->getFileUri())

Error when converting form Python 2. to Python 3

can you help me to convert this to python 3.5 ? I tried but it don't work. I did the following steps:
I change the package md5 to hashlib
I change all the id = md5.new("%s"%str(clf.get_params())).hexdigest() to id = hashlib.md5(("%s"%str(clf.get_params())).encode('utf-8') ).hexdigest()
but I still have somme problems when I put a directory to these parameters
save_preds="",
save_params=""
save_test_only=""
clf_name="XX"
I have the folowing error when I put something in thise parameters:
TypeError: a bytes-like object is required, not 'str'
Please see the code here:
blend_proba.py
Thanks,
cdk
Replacing
clf_name="XX"
by
clf_name=b"XX"
would convert the strings into objects of type bytes. Whether those changes will be enough, I honestly have no idea.

Windows, Ec2ServerCreate - Cannot set JSON attributes when running knife from Rails application

I am able to launch new instance at AWS from Ruby on Rails application (Chef::Knife::Ec2ServerCreate.new()). Works fine till I try to set JSON attributes. When I set them from command line and invoke knife.bat, it works.
Looking at ec2_server_create shows that command line option --json-attributes is mapped to symbol :json_attributes. I tried to set it using following code:
Chef::Config[:knife][:json_attributes] = "{'NodeName' : 'Node001'}"
and I get error:TypeError (no implicit conversion of Symbol into Integer):
As soon as I comment this single line, instance is created, registered with chef server and recipe is running.
Any suggestion how to set json attributes of first chef-client run?
PS
Sample code shows constant value for attribute, but actual value would be dynamically created.
Error message and code line where error occurs:
/chef/knife/core/bootstrap_context.rb:188:in `[]=': no implicit conversion of Symbol into Integer (TypeError)
Looking into source you can find:
def first_boot
(#config[:first_boot_attributes] || {}).tap do |attributes|
if #config[:policy_name] && #config[:policy_group]
attributes[:policy_name] = #config[:policy_name]
attributes[:policy_group] = #config[:policy_group]
else
attributes[:run_list] = #run_list #THIS LINE CAUSES EXCEPTION
end
attributes.merge!(:tags => #config[:tags]) if #config[:tags] && !#config[:tags].empty?
end
end
I set run list.
The issue is that json_attributes needs to be a hash, not a string. It isn't the #run_list that is failing, it is "{'NodeName' : 'Node001'}"[:run_list] which when you see in on place is probably a bit clearer.

GCE Python API: oauth2client.util:execute() takes at most 1 positional argument (2 given)

I'm trying to get started with the Python API for Google Compute Engine using their "hello world" tutorial on https://developers.google.com/compute/docs/api/python_guide#setup
Whenever making the call response = request.execute(auth_http) though, I get the following error signaling that I can't authenticate:
WARNING:oauth2client.util:execute() takes at most 1 positional argument (2 given)
I'm clearly only passing one positional argument (auth_http), and I've looked into oauth2client/util.py, apiclient/http.py, and oauth2client/client.py for answers, but nothing seems amiss. I found another stack overflow post that encountered the same issue, but it seems that in the constructor of the OAuth2WebServerFlow class in oauth2client/client.py, 'access_type' is set to 'offline' already (though to be honest I don't completely understand what's going on here in terms of setting up oauth2.0 flows).
Any suggestions would be much appreciated, and thanks in advance!
Looking at the code, the #util.positional(1) annotation is throwing the warning. Avoid it using named parameters.
Instead of:
response = request.execute(auth_http)
Do:
response = request.execute(http=auth_http)
https://code.google.com/p/google-api-python-client/source/browse/apiclient/http.py#637
I think documentation is wrong. Please use the following:
auth_http = credentials.authorize(http)
# Build the service
gce_service = build('compute', API_VERSION, http=auth_http)
project_url = '%s%s' % (GCE_URL, PROJECT_ID)
# List instances
request = gce_service.instances().list(project=PROJECT_ID, filter=None, zone=DEFAULT_ZONE)
response = request.execute()
You can do one of three things here:
1 Ignore the warnings and do nothing.
2 Suppress the warnings and set the flag to ignore:
import oauth2client
import gflags
gflags.FLAGS['positional_parameters_enforcement'].value = 'IGNORE'
3 Figure out where the positional parameter is being provided and fix it:
import oauth2client
import gflags
gflags.FLAGS['positional_parameters_enforcement'].value = 'EXCEPTION'
# Implement a try and catch around your code:
try:
pass
except TypeError, e:
# Print the stack so you can fix the problem, see python exception traceback docs.
print str(e)

Resources