Bug 1392878

Summary: Debug mode raises UnicodeDecodeError: 'utf8' codec can't decode byte 0x8d in position 7: invalid start byte
Product: [oVirt] ovirt-engine-sdk-python Reporter: Ondra Machacek <omachace>
Component: CoreAssignee: Ondra Machacek <omachace>
Status: CLOSED CURRENTRELEASE QA Contact: Aleksei Slaikovskii <aslaikov>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.0.2CC: bugs, juan.hernandez, lsvaty, mgoldboi
Target Milestone: ovirt-4.0.6Flags: rule-engine: ovirt-4.0.z+
lsvaty: testing_ack+
Target Release: 4.0.4   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-ovirt-engine-sdk4-4.0.4 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-01-18 07:29:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ondra Machacek 2016-11-08 12:12:27 UTC
Description of problem:
When running Python SDK in debug mode, Python SDK raises following exception:

UnicodeDecodeError: 'utf8' codec can't decode byte 0x8d in position 7: invalid  start byte

Version-Release number of selected component (if applicable):
4.0.2

How reproducible:
always

Steps to Reproduce:
1. Run following script:

---------------------------------
import logging

import ovirtsdk4 as sdk
import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='example.log')

connection = sdk.Connection(
    url='https://engine.example.com/ovirt-engine/api',
    username='admin@internal',
    password='password',
    ca_file='ca.pem',
    debug=True,
    log=logging.getLogger(),
)

vms_service = connection.system_service().vms_service()
vms = vms_service.list()
connection.close()
---------------------------------

Actual results:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ovirtsdk4/__init__.py", line 637, in _curl_debug
    text = data.decode('utf-8') if type(data) == bytes else data
  File "/usr/lib64/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xee in position 5: invalid continuation byte
Traceback (most recent call last):
  File "/tmp/list_vms.py", line 44, in <module>
    vms = vms_service.list()
  File "/usr/lib/python2.7/site-packages/ovirtsdk4/services.py", line 25275, in list
    response = self._connection.send(request)
  File "/usr/lib/python2.7/site-packages/ovirtsdk4/__init__.py", line 276, in send
    return self.__send(request)
  File "/usr/lib/python2.7/site-packages/ovirtsdk4/__init__.py", line 298, in __send
    self._sso_token = self._get_access_token()
  File "/usr/lib/python2.7/site-packages/ovirtsdk4/__init__.py", line 469, in _get_access_token
    sso_response['error']
ovirtsdk4.Error: Error during SSO authentication unsupported_grant_type : The authorization grant type is not supported by the authorization server.

Expected results:
Script successfully executed.

Additional info:

The problem is with pycurl version python-pycurl-7.19.0-17.el7.x86_64 and lower.
This problem was fixed in python-pycurl-7.19.0-18.el7.x86_64 tracked in following bug 1153321.

To support version python-pycurl-7.19.0-17 and lower we decided to fixed this problem using COPYPOSTFIELDS instead of POSTFIELDS to send HTTP POST data.