last day (17 days later) » 

7:58 AM
2
Q: Download a report using python

KobaI have a report that I want to download in a CSV format using a pyhton script. I searched the web for solutions, but none of them worked. This one looked very promising and simple, but unfortunately does not work either. Any ideas would be helpful. Update: Thats what I am trying to do when using...

 
@DanielBallinger I have seen it. In the link I provided the same approach is used I believe (to get a report use the report links). I have been looking at the different ways of downloading files in python using urllib, urllib2, httplib, and others, but did not come up with a solution yet.
 
Any error messages when you try to run the solution from the linked article?
 
@FrankZ Not and error msg, but I get weird output. I updated my question.
 
Works for me. Are you sure that a) the login was successful and b) your application is on the na2 instance?
 
@FrankZ It does? Hmm weird. Yeah I am sure about it. I will double check. How does your output looks like?
 
7:58 AM
What's the output if you add these two lines after the first request? (and add an 'import json' of course) print l.status_code print json.dumps(dict(l.headers), indent=4)
 
@FrankZ here is the output
 
Can't see anything wrong with that. When you look at the content of l.text, does it contain a reference to na2.salesforce.com? It should be part of the javascript (key "inst" of SFDCSessionVars)
 
 
6 hours later…
2:03 PM
Hey. I appreciate your help. I will check and get back to you.
 
2:14 PM
I just checked and it says that I need to activate the device I am trying to login from. I guess I should do something like adding the ip address of my laptop to salesforce. I will try.
 
2:29 PM
So I added the ip range to my salesforce org that includes my ip. Now, I have another issue. When I print out the l.text it say I dont have javascript enabled. I have a little idea how to go about this one.
 
 
3 hours later…
5:56 PM
Take a close look. Isn't that message included in <noscript> tags? There should be some javascript above that. Look in there.
 
 
2 hours later…
7:40 PM
@FrankZ Yeah you are right, it is in noscript tag. I looked at the javascript output above. Iam not sure what it means. Here it is pastebin.com/pTKf6biS
 
 
1 hour later…
rao
8:54 PM
@koba is it a hard requirement that you need to use python to export or is the requirement more on exporting the report as CSV?
 
9:22 PM
@rao I prefer python because after exporting I want to do some manipulation to the csv. However, for the export part I could use any other way I guess. You have suggestions?
 
rao
10:01 PM
@koba
did you take a look at the second approach suggested by SFDCFOX
i know how to email the report as CSV
I need to figure out how to stitch the API and export as CSV part together
 
10:21 PM
@rao it works using Python. I was successful using the approach here, but I don't understand why it doesn't work for @koba. The only difference I can see is that I didn't use the enc parameter in the CSV export request.
@koba does that url to export the report work in the browser once you're logged in?
 

  last day (17 days later) »