-
Notifications
You must be signed in to change notification settings - Fork 264
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
TypeError: startswith first arg must be bytes or a tuple of bytes, not str #111
Comments
I was able to modify /usr/local/lib/python3.5/dist-packages/winrm/init.py and make the following adjustment: Before: After: |
I hit the same issue, but my tweak was a little different: I am on python3.4 and version 0.2.0
Output:
Changing code as suggested above gave me this message:
So... warning looked suspicious.. I removed the b I changed the message before it went into I changed rs.std_err in from: I now have a clean output. Hope this helps. |
I had the same result as bikerider262 and the same fix worked for me. |
If anyone is looking for a quick monkey patch based on @bikerider262's solution, this worked for me
|
The fix above did clean things up so it would run but then I found that if there was an error returned from PS, I just get a nice exception message. Appears there is an underlying issue with what data type is being used. Warning: there was a problem converting the Powershell error message: cannot use a bytes pattern on a string-like object I was able to remove the exception to (maybe??) find where the true error is however I am not knowledgeable enough to resolve it. File "C:\Python\Python36\lib\site-packages\winrm_init_.py", line 54, in run_ps after also modifying p = re.compile('xmlns=[""][^\"\"][""]') In attempts to resolve Warning: there was a problem converting the Powershell error message: cannot use a string pattern on a bytes-like object Hopefully someone else understands how to properly clean up the data type in this scenario. |
This should fix the issue diyan#111
@bikerider262 @JPvRiel @almightyfoon Why do you think that output is UTF-8? I'm sure that even default PowerShell output encoding is UTF-8. It works in this particular case just because your output is ASCII and it's subset of UTF-8, i.e. ASCII string is UTF-8 string. But reverse is not true at all. Would it work with Chinese, Greek or Cyrillic output? As @programmerchad pointed out, correct way is to handle output as bytes simply using bytes type explicitly: |
Hi everybody, The issue is relative to the codepage you choose at the openshell invocation.
The correct test is:
And may be the codepage 65001 should the default and the only choice because you're sure of what you expect. So it works whether your error results contains chineese or armenian characters. If you choose the codepage 437 which is the default, the original test works.
which failed. Sorry i've no time to do more investigations, if you do have any questions, do not hesitate. PS: Once fix there is another issue for pretty error printing, it's the default shell width (80 chars). |
addressed via #222 |
python 3, winrm version 0.2
code
If command is 'ls C:/a/b' ,then success.
Traceback
The text was updated successfully, but these errors were encountered: