On 02/21/2012 01:10 PM, Tony Pelletier wrote:
Hi,I'm struggling with what I think seems to be a problem. I've created a program that does numerous SOAP calls. In short, I create a report on a report server, pull that file down then parse that file that's been written locally for data to make more SOAP calls. My problem is I'm grabbing the filename then losing it somewhere along the way. The only thing I can think of is that it's still open/being written and causing me a problem. Main starts like such. def main(): service = Service() cleanup() reportId = createReport(service) #time.sleep(3) filename = getReport(service,reportId) getEventAttachments(service, filename) Here are the results from a test run. Deleting "files" directory... "files" directory successfully created... Report in Processing state... WeeklyDeliveriesReport_2012-02-21.csv WeeklyDeliveriesReport_2012-02-21.csv report succesfully written out... None File still being written out... getReport() returns a filename and you actually see it twice up in the results. def getReport(service, reportId): reportIds = service.client.factory.create('ArrayOfstring') reportIds.string.append(reportId) try: result = service.client.service.ReportQueryById(reportIds, 'True') if result.Report[0].ReportStatus == 'Processing': print 'Report in Processing state...' time.sleep(3) getReport(service,reportId) else: filename = result.Report[0].ReportFileArgs.ReportFileArg[0].UserFileName print filename encodedfile = result.Report[0].ReportFileArgs.ReportFileArg[0].EncodedValue encodedstring = encodedfile.encode('utf-8') str_list = [] for line in encodedstring: line = line.rstrip() str_list.append(line) string = ''.join(str_list) data = base64.b64decode(string) outfile = open(filename, 'w') outfile.write(data) outfile.close() shutil.copyfile(filename, os.path.join('files', filename)) print filename + ' report succesfully written out...' logging.info(filename + ' report succesfully written out...') return filename except suds.WebFault as e: print e.fault.detail then from main, I'm using filename to then make the call to getEventAttachments and passing in filename. The None you see is a result of my "print filename" statement. Now, if I uncomment that time.sleep(3), it runs flawlessly which I think tells me that the file is still being written to. I *think*... Two questions. 1. Is that not it and if so, am I missing something obvious? 2. If it is it, is there a way to check to see if the file I'm trying to read from is done being written to? Thanks Tony
Please post your message again, as a text message rather than an html one. Reading non-trivial python code that's lost all its indentation is impossible. You've done it before, but that case was simple enough to not matter much.
-- DaveA _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
