Python Forum
'NoneType' object has no attribute 'encode'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'NoneType' object has no attribute 'encode'
#7
An error message without context is not very useful. There is only one place "encode" is used in this code.
    report_element = response.find("report")
    # get the full content of the report element
    content = report_element.find("report_format").tail
 
    # convert content to 8-bit ASCII bytes
    binary_base64_encoded_pdf = content.encode('ascii')
The message you are receiving would indicate that "content" is None, which would indicate that this report_element.find("report_format").tail returns None.

I do not know why that would return None. Is the problem that "report_element" could not find "report_format" and thus the "tail" is not defined? Why would that be? Is this what happens when the requested report could not be found? We have no way to know since we don't know anything at all about pdf-report.gmp.py.

This code looks like it is part of a package, a commercial software package. I assume the code works, but you have not provided that information. If the code works then the problem is either that it cannot find the report, or that the report is not in a format that could be processed. In either case I would expect better reporting, but the script just assumes everything is fine and doesn't appear to do any error reporting at all.

Sorry that I can't help you any more.
Reply


Messages In This Thread
RE: 'NoneType' object has no attribute 'encode' - by deanhystad - Nov-05-2020, 03:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 807 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  encode/decode to show correct country letters in a CTk combobox janeik 2 770 Sep-02-2023, 09:46 AM
Last Post: janeik
  TypeError: 'NoneType' object is not callable akbarza 4 1,117 Aug-24-2023, 05:14 PM
Last Post: snippsat
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,855 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,626 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 4,088 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 791 Jun-14-2023, 12:37 PM
Last Post: deanhystad
Question UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 562: ord ctrldan 23 5,108 Apr-24-2023, 03:40 PM
Last Post: ctrldan
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,498 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,881 Feb-17-2023, 06:01 PM
Last Post: Sameer33

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020