reportportal / agent-Python-RobotFramework

Robot Framework integration for Report Portal
Apache License 2.0
59 stars 33 forks source link

ascii error #21

Closed jevm closed 3 years ago

jevm commented 6 years ago

I am running a robot framework from RIDE, trying to set up a report portal reporting to robot framework. My command line is:

--listener robotframework_reportportal.listener --variable RP_UUID:9a10eub9-e451-470d-a3f4-2409d5c45cbc --variable RP_ENDPOINT:http://192.168.99.100:8080 --variable RP_LAUNCH:pybot_TEST_EXAMPLE --variable RP_PROJECT:tbd_robot And I am getting an error in ride console:

[ ERROR ] Calling method 'start_keyword' of listener 'robotframework_reportportal.listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u0101' in position 29: ordinal not in range(128)

What could be wrong here? After this error appears, all further activity and calling all methods goes with it, suite remains unfinished in ReportPortal.

evjlobanova commented 6 years ago

@jevm unfortunately we do not have any contributors on python now. So maybe you want to contribute RP? Also we have a channel in our Slack chat with Python discussion, I suppose it can be useful https://reportportal.slack.com/messages/C9PMAA690

krasoffski commented 6 years ago

The root cause might be incorrect Unicode handling by listener.

The issue above says, that UnicodeEncodeError: 'ascii' codec can't encode character u'\u0101' in position 0: ordinal not in range(128).

u'\u0101' is equivalent of ā

The issue appears (need traceback for better understanding) in following part of code:

def start_keyword(name, attributes):
    parent_type = "SUITE" if ParentTypes.is_empty() else ParentTypes.peek()
    kwd = Keyword(name=name, parent_type=parent_type, attributes=attributes)
    logging.debug("ReportPortal - Start Keyword: {0}".format(attributes))
RobotService.start_keyword(keyword=kwd)

Here is a example how to get similar error:

ch = u'\u0101'
"ReportPortal - Start Keyword: {0}".format(ch)

In this case fix is obvious, but I don't have ability to check.

jevm commented 6 years ago

@krasoffski @evjlobanova Thank you for your responses, unfortunately, I am only a beginner with python. Maybe you could tell me what fix it could in this case, and what additional information I could provide? What is interesting, when I have this error, it goes not only for start keyword, but for every method, like end_keyword, end_suite, etc.

[ ERROR ] Calling method 'end_keyword' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128) [ ERROR ] Calling method 'end_keyword' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128) [ ERROR ] Calling method 'end_keyword' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128) [ ERROR ] Calling method 'start_keyword' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128) [ ERROR ] Calling method 'log_message' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128)

, it seems to be stuck and then the whole execution crashes in the end. I am running robot framework under windows7 machine with python portable 2.7.2.1. I have a thought to try it out with newest python 3 and see what happens then.

krasoffski commented 6 years ago

@jevm I will try to perform fix and share with you for testing, but only after Sunday. What do you think about this? It is true

it goes not only for start keyword, but for every method because each method contains such logging instruction, "ReportPortal - * Keyword: {0}".format(ch)

jevm commented 6 years ago

@krasoffski

Thank you very much, but will you be able to show me places in the code where it was fixed? The thing is, we are both trying this agent and the https://github.com/ailjushkin/robotframework-reportportal-ng/, so I would try fixing it as well as they should be similar.

krasoffski commented 6 years ago

@jevm You can try to perform following steps (one modification per step and then check) for file: robotframework_reportportal/listener.py

  1. The first one is to add
    • Add from __future__ import unicode_literals
    • Specify encoding # -*- coding: utf8 -*-
  2. Comment out all lines like: logging.debug("ReportPortal - Start Launch: {0}".format(attributes)). I suspect that issue related to converting non-ascii char within format instructions.
jevm commented 6 years ago

@krasoffski

So my file beginning should look like

import logging

from .variables import Variables
from .model import Keyword, Test, Suite, LogMessage
from .service import RobotService
from __future__ import unicode_literals
# -*- coding: utf8 -*-

Is it correct?

As for the second step - do I understand this correctly that this funcionality is just a debug logging which isn't neccesary for a main functionality?

krasoffski commented 6 years ago

Two first lines of the file:

# -*- coding: utf8 -*-
from __future__ import unicode_literals

import logging

from .variables import Variables
from .model import Keyword, Test, Suite, LogMessage
from .service import RobotService

As for the second step - do I understand this correctly that this funcionality is just a debug logging which isn't neccesary for a main functionality?

It seems like yes.

jevm commented 6 years ago

@krasoffski the proposed solution with step 1 didn't help, I will try Python 3 and then try the second step if it won't be helpful

krasoffski commented 6 years ago

@jevm, Does the issue appear in the same function with step1? I did not use RobatFramework for while, thus probably @ailjushkin might help with this.

@ailjushkin I suspect that root cause is converting non-ascill char to ascii performed by default in Python2 (like label, comments, keyword names, etc). If you familiar with RobatFramework for now, could you please take a look (if you have a time).

jevm commented 6 years ago

Yes, the same situation

[ ERROR ] Calling method 'start_keyword' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128)

[ ERROR ] Calling method 'log_message' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128)

[ ERROR ] Calling method 'end_keyword' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128)

[ ERROR ] Calling method 'log_message' of listener 'reportportal_listener' failed: UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 817: ordinal not in range(128)
jevm commented 6 years ago

@krasoffski I've registered a similar issue for @ailjushkin robotframework-reportportal-ng, as it is the same there.

macervera commented 6 years ago

I have the same problem and solve it changing the variable RP_ENDPOINT.

First i put http://myserver:8080/ui/ (this don't work), the problem is that the service is waiting for a JSON and the server returns a html with a 404 errror, then fails with a ascii error.

I change to: http://myserver:8080 (this work)

I hope this help to you.

Regards,