reportlab - bad argument to internal function error in python -


i have python script uses reportlab create report, script has been tested , works expected on occasions following error message

traceback info:  file "c:\tools\legionellatool.py", line 605, in <module>  createreport(selectedcoolingtowers, report_outputs_folder, dbo_colgis, openpdf)  error info:  ..\objects\moduleobject.c:50: bad argument internal function 

line 605 createreport(selectedcoolingtowers, report_outputs_folder, dbo_colgis, openpdf)

createreport function ...creates report. have debugged through code , havent got errors, might make error appear, error happens on occasions whereas on other occasions report created fine.

edit===== createreport code

def createreport(myreporttable, myreportfolder, m3table, openpdf):     global author     global timestamp  ##    myreporttable = gp.getparameterastext(0) ##    myreportfolder = gp.getparameterastext(1) ##    m3table = gp.getparameterastext(2) ##    openpdf = gp.getparameterastext(3)      author = getpass.getuser() #gets os user name     timestamp = str(datetime.datetime.now().hour) + ':' + str(datetime.datetime.now().minute) + ' on ' + str(datetime.date.today().day) + '/' + str(datetime.date.today().month) + '/' + str(datetime.date.today().year)       #add time stamp file name     myfile = myreportfolder + os.sep + 'coolingtowersforinspection_' + str(datetime.datetime.now().hour) + '_' + str(datetime.datetime.now().minute) + '_' + str(datetime.date.today().day) + '_' + str(datetime.date.today().month) + '_' + str(datetime.date.today().year) + '.pdf'     c = reportlab.pdfgen.canvas.canvas(myfile)      #creates sectors array     sectors = []     sectors.append('nw')     sectors.append('ne')     sectors.append('sw')     sectors.append('se')      sector in sectors:         #sector header         #framepage(c, 'cooling towers inspection - ' + sector + ' sector')         title = 'cooling towers inspection - ' + sector + ' sector'         c.setfont('helvetica',20) #title font         c.drawstring(reportlab.lib.units.inch, 10.5 * reportlab.lib.units.inch, title) #creates title          c.setfont('helvetica',10) #header , footer font          #creates header         c.drawcentredstring(4.135 * reportlab.lib.units.inch, 0.75 * reportlab.lib.units.inch,                                  'report generated ' + author + ' @ ' + timestamp + ' - page %d' % c.getpagenumber())          #creates footer         c.drawcentredstring(4.135 * reportlab.lib.units.inch, 11.00 * reportlab.lib.units.inch,                                 'environmental services')          #draw border         c.setstrokecolorrgb(1,0,0)         c.setlinewidth(5)         c.line(0.8 * reportlab.lib.units.inch, reportlab.lib.units.inch, 0.8 * reportlab.lib.units.inch, 10.75 * reportlab.lib.units.inch)          #reset afterwards         c.setlinewidth(1)         c.setstrokecolorrgb(0,0,0)          c.setfont('helvetica', 10)          #gets towers in sector         mytowers = arcpy.searchcursor(myreporttable,"\"sector\" = '" + sector + "'","","")         seltower = mytowers.next()          y = 730          if seltower not none:              while seltower:                 #insert page break when close end of page                 if y < 110:                     c.showpage()                     y = 730                     framepage(c, 'cooling towers inspection - ' + sector + ' sector')                  if seltower.tower_name <> none:                     c.drawstring(100, y, string.strip(seltower.tower_name))                 else:                     c.drawstring(100, y, "na")                 y = y - 12                  if seltower.tower_address <> none:                     c.drawstring(100, y, string.strip(seltower.tower_address))                 else:                     c.drawstring(100, y, "na")                 y = y - 12                  c.drawstring(100, y, "number of towers: " + str(int(seltower.number_of_towers)) + " ;   m3 code: " + seltower.ukey + " ;   distance band: " + str(int(seltower.distance)) + " meters")                 y = y - 12                  inspectstring = ""                 if seltower.tower_rating <> none:                     inspectstring = "inspection rating: " + seltower.tower_rating                 else:                     inspectstring = "inspection rating: na;"                  if seltower.tower_last_inspection <> none:                     t = seltower.tower_last_inspection                     strlastinspection = t.strftime("%a, %d %b %y")                      inspectstring = inspectstring + "   last inspection: " + strlastinspection                     #inspectstring = inspectstring + "   last inspection: " + seltower.tower_last_inspection                 else:                     inspectstring = inspectstring + "   last inspection: na"                  c.drawstring(100, y, inspectstring)                 y = y - 12                  c.drawstring(100, y, "contacts:")                 y = y - 12                  mytowerukey = seltower.ukey                  #gets contacts cooling tower                             mytowercontacts = arcpy.searchcursor(m3table,"\"ukey\" = '" + mytowerukey + "'","","")                  selcontact = mytowercontacts.next()                  while selcontact:                     if y < 110:                         c.showpage()                         y = 730                         framepage(c, 'cooling towers inspection - ' + sector + ' sector')                      contact = ""                     if selcontact.title <> none:                         if string.strip(selcontact.title) <> "":                             contact = string.strip(selcontact.title) + " "                     if selcontact.firstname <> none:                         contact = contact + selcontact.firstname + " "                     if selcontact.familyname <> none:                         contact = contact + selcontact.familyname + " "                     if selcontact.jobtitle <> none:                         contact = contact + "(" + selcontact.jobtitle + ") "                     if selcontact.telw <> none:                         contact = contact + selcontact.telw + "(work) "                     if selcontact.mobile <> none:                         if string.strip(selcontact.mobile) <> "":                             contact = contact + string.strip(selcontact.mobile) + "(mobile) "                     if selcontact.telh <> none:                         if string.strip(selcontact.telh) <> "":                             contact = contact + string.strip(selcontact.telh) + "(home)"                      contact = string.strip(contact)                      c.drawstring(100, y, contact)                     y = y - 12                     selcontact = mytowercontacts.next()                                  y = y - 12                 del mytowercontacts                 seltower = mytowers.next()         else:             c.drawstring(100, y, "no cooling towers inspection in sector")          c.showpage() #insert page break after each sector      del mytowers      c.save()      if openpdf == "true":         os.startfile(myfile)  #function creates each page def framepage(canvas, title):     canvas.setfont('helvetica',20) #title font     canvas.drawstring(reportlab.lib.units.inch, 10.5 * reportlab.lib.units.inch, title) #creates title      canvas.setfont('helvetica',10) #header , footer font      #creates header     canvas.drawcentredstring(4.135 * reportlab.lib.units.inch, 0.75 * reportlab.lib.units.inch,                              'report generated ' + author + ' @ ' + timestamp + ' - page %d' % canvas.getpagenumber())      #creates footer     canvas.drawcentredstring(4.135 * reportlab.lib.units.inch, 11.00 * reportlab.lib.units.inch,                             'environmental services')      #draw border     canvas.setstrokecolorrgb(1,0,0)     canvas.setlinewidth(5)     canvas.line(0.8 * reportlab.lib.units.inch, reportlab.lib.units.inch, 0.8 * reportlab.lib.units.inch, 10.75 * reportlab.lib.units.inch)      #reset afterwards     canvas.setlinewidth(1)     canvas.setstrokecolorrgb(0,0,0) 

edit number 2 *

full traceback here

traceback (most recent call last):   file "c:\tools\legionellatool.py", line 613, in <module>     createreport(selectedcoolingtowers, report_outputs_folder, dbo_colgis, openpdf)    file "c:\tools\legionellatool.py", line 120, in createreport      c.drawstring(reportlab.lib.units.inch, 10.5 * reportlab.lib.units.inch, title) #creates title    file "c:\python26\arcgis10.0\lib\site-packages\reportlab\pdfgen\canvas.py", line 1481, in drawstring      t.textline(text)    file "c:\python26\arcgis10.0\lib\site-packages\reportlab\pdfgen\textobject.py", line 426, in textline      self._code.append('%s t*' % self._formattext(text))   file "c:\python26\arcgis10.0\lib\site-packages\reportlab\pdfgen\textobject.py", line 393, in _formattext      f, t in pdfmetrics.unicode2t1(text,[font]+font.substitutionfonts): systemerror: ..\objects\moduleobject.c:50: bad argument internal function  <type 'exceptions.systemexit'>: 1 

thanks

in experience, intermittent errors reportlab caused problems when trying rendering text may have 'weird' in it, unexpected characters character set or nulls. looking through code didn't notice cause problem, might want possibility contains unexpected value.

in particular, i'd take @ code dealing selcontact , see if of attributes unexpectedly null or not strings lead errors.

without full stack trace, it's hard more specific.

eta

based on provided stack trace, looks problem must either going title variable trying draw or font being used draw string. looking @ code don't notice problems, though, , nothing suggest intermittent problem part of code throwing error.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -