pymarc generates AttributeError: 'str' object has no attribute 'decode'

510 views
Skip to first unread message

Lee LeBlanc

unread,
Nov 5, 2016, 6:47:30 PM11/5/16
to pymarc Discussion
Hi All, 

Trying to run this script markbart.py but I'm getting this error below. I think this is about pymarc perhaps holding things up. If my question sounds strange that's because my knowledge of python mostly comes from watching nature documentaries and living close to the Florida Everglades

  File "marckbart.py", line 27, in <module>
    for record in reader:
  File "C:\Program Files\Python36-32\lib\site-packages\pymarc\reader.py", line 97, in __next__
    utf8_handling=self.utf8_handling)
  File "C:\Program Files\Python36-32\lib\site-packages\pymarc\record.py", line 74, in __init__
    utf8_handling=utf8_handling)
  File "C:\Program Files\Python36-32\lib\site-packages\pymarc\record.py", line 231, in decode_marc
    self.leader = marc[0:LEADER_LEN].decode('ascii')
AttributeError: 'str' object has no attribute 'decode'

Tried changing the file encoding to UTF-8. And I first cleared this error about file -which is no longer supported -and should read open? I think I understand that this bit of code must read 
fd = open(SRC_DIR + '/' + item, 'r') instead of file.

Any help appreciated -thanks!

Geoffrey Spear

unread,
Nov 6, 2016, 9:14:07 AM11/6/16
to pym...@googlegroups.com
Hi Lee,

In Python 3, you need to open the file in 'rb' mode, since MARC is a binary format and the Python 3 open() with 'r' mode would do decoding to unicode (called "str" in py3) objects.

(In Python 2, 'r' mode only affected newline translation in Windows and did nothing at all on other platforms, so either mode would work the same.)

--
Geoffrey Spear
Metadata Manager
Health Sciences Library System
University of Pittsburgh

--
You received this message because you are subscribed to the Google Groups "pymarc Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymarc+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lee LeBlanc

unread,
Nov 7, 2016, 9:30:15 AM11/7/16
to pymarc Discussion
Appreciate that Geoffrey -Now on to the next error!
Lee
To unsubscribe from this group and stop receiving emails from it, send an email to pymarc+un...@googlegroups.com.

Benjamin Abrahamse

unread,
Mar 20, 2018, 7:08:06 PM3/20/18
to pymarc Discussion
This just solved my problem!

To unsubscribe from this group and stop receiving emails from it, send an email to pymarc+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages