PyMarc Invalid Literal Error

369 views Asked by At

I'm trying to parse a MARC file downloaded from the Library of Congress. I've successfully downloaded the record using the PyZ3950, but when I try to parse the file using PyMarc, I get the following error:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    for record in reader:
  File "build/bdist.macosx-10.9-intel/egg/pymarc/reader.py", line 83, in next
ValueError: invalid literal for int() with base 10: '<PyZ3'

And here is my full code:

from PyZ3950 import zoom, zmarc
from pymarc import MARCReader

conn = zoom.Connection('z3950.loc.gov', 7090)
conn.databaseName = 'VOYAGER'
conn.preferredRecordSyntax = 'USMARC'

query = zoom.Query('CCL', 'ti="1066 and all that"')

res = conn.search(query)

reader = MARCReader(str(res))
for record in reader:
        print record.title()

conn.close()
1

There are 1 answers

0
jgrocha On BEST ANSWER

Your statement:

res = conn.search(query)

return a ResultSet, accordingly to http://www.panix.com/~asl2/software/PyZ3950/zoom.html

Each record r in the resultSet have the data in r.data

So, you have to feed the MARCReader with each r.data or with them all concatenated.

This will work:

from PyZ3950 import zoom, zmarc
from pymarc import MARCReader
conn = zoom.Connection('z3950.loc.gov', 7090)
conn.databaseName = 'VOYAGER'
conn.preferredRecordSyntax = 'USMARC'
query = zoom.Query('CCL', 'ti="1066 and all that"')
res = conn.search(query)
marc = ''
for r in res:
    marc = marc + r.data
reader = MARCReader(marc)
for record in reader:
        print record.title()
conn.close()