Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange problem with a WMI query and non ascii characters #187

Closed
Mazwak opened this issue Feb 19, 2016 · 6 comments
Closed

Strange problem with a WMI query and non ascii characters #187

Mazwak opened this issue Feb 19, 2016 · 6 comments

Comments

@Mazwak
Copy link
Contributor

Mazwak commented Feb 19, 2016

Following #143 , I now have a problem I can't debug.

I'm still using the same query :
ASSOCIATORS OF {Win32_Directory.Name="#{path}"} WHERE AssocClass = Win32_Subdirectory ResultRole = PartComponent

When the path contains 'é', and most likely other accented characters, I get an error :
WinRM/lib/winrm/http/response_handler.rb:79:inraise_transport_error': Bad HTTP response returned from server (400). (WinRM::WinRMHTTPTransportError)`

The SOAP response is indeed bad, in fact totally empty :

#<HTTP::Message:0x00556505f40be0 
  @http_header=
    #<HTTP::Message::Headers:0x00556505f40bb8
      @http_version="1.1",
      @body_size=0,
      @chunked=false,
      @request_method="POST",
      @request_uri=#<URI::HTTP http://shydfiler:5985/wsman>,
      @request_query=nil,
      @request_absolute_uri=nil,
      @status_code=400,
      @reason_phrase=nil,
      @body_type=nil,
      @body_charset=nil,
      @body_date=nil,
      @body_encoding=nil,
      @is_request=false,
      @header_item=[["Server", "Microsoft-HTTPAPI/2.0"], ["Date", "Fri, 19 Feb 2016 17:00:39 GMT"], ["Connection", "close"], ["Content-Length", "0"]],
      @dumped=false>,
    @peer_cert=nil,
    @http_body=#<HTTP::Message::Body:0x00556505f40b40
      @body="",
      @size=0,
      @positions=nil,
      @chunk_size=nil>,
    @previous=nil>

The exact query is :
ASSOCIATORS OF {Win32_Directory.Name="e:\\Maldi-Tof\\ESEC\\doc périmés"} WHERE AssocClass = Win32_Subdirectory ResultRole = PartComponent

Running the query remotely from windows seven works.

I've been searching the whole afternoon, but to no avail.

Do you have an idea ?

@Mazwak Mazwak changed the title Strange problem with a WMI query Strange problem with a WMI query and non ascii characters Feb 19, 2016
@sneal
Copy link
Member

sneal commented Feb 19, 2016

Have you tried playing with the locale option?

@Mazwak
Copy link
Contributor Author

Mazwak commented Feb 22, 2016

Locale did not change anything.

However, after 3 hours, I got it working. I think it comes from the message size, where you use the number of characters, instead of the size in bytes.

In http_transport, line 168 :
original_length = message.bytesize

Does it looks good to you ?

@sneal
Copy link
Member

sneal commented Feb 22, 2016

Ah hah! So we have some double byte characters causing the message length != message byte size I presume.

@Mazwak
Copy link
Contributor Author

Mazwak commented Feb 23, 2016

Yes, as UTF-8 uses 1 to 4 bytes for a single characters.

'é' uses 2, in "Docs périmés".

I did not search winrm documentation, but it is most likely expecting the size of the message in bytes, and not the number of character. Which makes sense.

@sneal
Copy link
Member

sneal commented Feb 23, 2016

I found this in the WSMV spec: Content-Length: Contains the size, in bytes, of the message body. It MUST be present. Do you mind sending a PR?

@Mazwak
Copy link
Contributor Author

Mazwak commented Mar 2, 2016

Done

mwrock added a commit that referenced this issue Mar 2, 2016
Problem when message has multibyte characters (#187)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants