robocorp / rpaframework

Collection of open-source libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework and Python
https://www.rpaframework.org/
Apache License 2.0
1.13k stars 216 forks source link

Error on List Messages in ImapSmtp #1086

Open boanerxe opened 11 months ago

boanerxe commented 11 months ago

I’m getting the following error when trying to “List Messages” using the RPA.ImapSmtp library and trying to filter by subject: LookupError: unknown encoding: None

This is the code I’m using: ${emails}= List Messages source_folder=INBOX criterion=SUBJECT “invoice” FOR ${email} IN @{emails} Log To Console ${email}[Subject] Log To Console ${email}[From] Log To Console ${email}[Date] Log To Console ${email}[Has-Attachments] END

Did any of you find this error? Any clue to solve it?

Thanks!

mikahanninen commented 11 months ago

Hi @boanerxe . Thank you for the report. I can look into that later, but first question is the quotes around "invoice". To me, it doesn't seem to have normal quotes around it, which could cause encoding problem.

your quotes (my quotes above in the message) “invoice”

boanerxe commented 11 months ago

Hi @mikahanninen. Thank you for your answer. The different quotes around invoice are because I also posted this question on the robocorp forum and copied the text from there. For some reason the quotes changed when I posted in the forum, but on Visual Studio I'm using the right quotes. You have a sharp eye for catching that :)

mikahanninen commented 11 months ago

@boanerxe 😄 ok. What is your rpaframework version ?

boanerxe commented 11 months ago

I'm using rpaframework 22.5.3

mikahanninen commented 11 months ago

Can you modify your robot.yaml so that robot is executed with TRACE logging enabled ? and then post the detailed exception message here ?

into the robot.yaml

shell: python -m robot -L TRACE --report NONE --outputdir output --logtitle "Task log" tasks.robot
boanerxe commented 11 months ago

I did, but nothing changed ( I don't get an exception). Also, in the meantime I updated rpaframework to the last version (just in case). Here is the output:

PS C:\Users\Santi\iCloudDrive\Visual Studio Projects>  c:; cd 'c:\Users\Santi\iCloudDrive\Visual Studio Projects'; & 'C:\Users\Santi\AppData\Local\robocorp\temp\8ef8ffe067944b01\rf-ls-run\run_env_00_tozluem4.bat' '-u' 'c:\Users\Santi\.vscode\extensions\robocorp.robotframework-lsp-1.11.0\src\robotframework_debug_adapter\run_robot__main__.py' '--port' '53134' '--no-debug' '--listener=robotframework_debug_adapter.events_listener.EventsListenerV2' '--listener=robotframework_debug_adapter.events_listener.EventsListenerV3' '--pythonpath' 'c:\Users\Santi\iCloudDrive\Visual Studio Projects\rpa_descarga_facturas\.' '--prerunmodifier=robotframework_debug_adapter.prerun_modifiers.FilteringTestsSuiteVisitor' 'c:\Users\Santi\iCloudDrive\Visual Studio Projects\rpa_descarga_facturas\tasks.robot' 
==============================================================================
Tasks :: Este RPA tiene como objetivo descargar todas las facturas generada...
==============================================================================
#1   Buscar facturas en correo                                        | FAIL |
LookupError: unknown encoding: None
------------------------------------------------------------------------------
[ WARN ] Graphviz executable not found: failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH
Tasks :: Este RPA tiene como objetivo descargar todas las facturas... | FAIL |
1 task, 0 passed, 1 failed
==============================================================================
Output:  C:\Users\Santi\iCloudDrive\Visual Studio Projects\output.xml
Log:     C:\Users\Santi\iCloudDrive\Visual Studio Projects\log.html
Report:  C:\Users\Santi\iCloudDrive\Visual Studio Projects\report.html

image

boanerxe commented 11 months ago

I think I have located the source of the error on the file ImapSmtp.py.

On the function get_decoded_email_body: If the message is not multipart, you are calling the function:

text = str(
                message.get_payload(decode=True),
                content_charset or self.encoding,
                "ignore",
            )

But, if the message is multipart, the function changes to this:

_data = str(payload, str(content_charset), "ignore")

If you change str(content_charset) by content_charset or self.encoding, I stop receiving the error relative to encoding.

@mikahanninen, could you check if this is correct? In that case can you change the code for following versions?