Download file from Box - python

I am new to box, trying to upload and download file from the box using boxsdk uploading file is working fine for me. I got stuck with downloading file.
I have written code to download file as follows:
with open('destinationfilepath','wb') as file_object:
client.file('boxfileId').download_to(file_object)
file_object.close()
It's printing content of my file and finally getting error
as Nonetype object has to attribute 'readline' leaving with no content in destination file.

Just in case anyone stuck with this, I got it working by updating all pip packages I had, may be because of version mismatch it was not working.

Related

Is it safe to save files in python library?

I wanted to use python turtle and the code didn't work, until I saved the file in the python library. (it didn't work earlier giving an error message saying 'turtle' is not recognised)
When i saved the file in the library, i saved the file as “hello23.py” but it got saved in the library as "pytube-pytube-v12.0.0-0-ge85.py”
It's been saved by the same name of the pytube file. (“pytube” is the package used to download YouTube videos by python.) Why is that?
And I saved another file again by creating a new folder in the library. it got saved fine.
My OS is Mac, Is it safe to save files in the library? I’ve heard not to save user files in the library.

Files downloaded from Dropbox API come as a Zip

I am trying to download a file from my Dropbox account, however, on Linux (Raspbian) when I execute the line:
dbx = dropbox.Dropbox(TOKEN)
dbx.files_download_to_file(LOCAL_PATH,r'/file.ppsx')
It is downloaded as a zip. I do not have this problem executing the code on Windows. I'd like to note the file is a .ppsx, a PowerPoint presentation file. I have no problem downloading it manually from Dropbox. My question is, how can I circumvent this problem and download it unzipped?
It seems that Dropbox sent the file not as a zip, but rather changed the name of the file to the directory of where it was installed. I circumvented this problem by using the os.rename module. This solved the problem and allowed me to open the file within the same script.

pdf2image.exceptions.PDFPageCountError: Unable to get page count. error

Hello i am working on a project(converting pdf to jpeg images),i am using the pdf2img module in python for the same.But i am getting an error here:
images=convert_from_path(filename,poppler_path=r'C:\Program Files\Library\bin')
the error which i used to get in the beginning was poppler was not in path,but after correcting it now i am getting the error:
pdf2image.exceptions.PDFPageCountError: Unable to get page count.
Kindly help me to resolve this issue,
from pdf2image import*
the module i used is pdf2image
I had the same issue and solved it by installing Microsoft Visual C++ Redistributable which was missing from my computer (download here). You can check that the program pdfinfo.exe works fine, by running it from your console (the program is located in the Library/bin folder of poppler). If it fails, you will get the real error, otherwise it's caught and silenced by pdf2image.py telling you it could not get the page count.
Haw, I also encountered this problem.
This problem occurs if the script is executed on IDE, If you execute the script in the folder, There will be no problem.
Maybe it's the execution path.
from pdf2image import convert_from_path
images=convert_from_path("pdf_file_path_with_name",poppler_path="")
for i in range(len(images)):
images[i].save('image_name'+ str(i) +'.jpg', 'JPEG')
The reason could be if your PDF file path is not proper or broken. In my problem I solved this by changing quotes to single quote in file path. Maybe this is something related with encoding.
If you dive into pdf2image code, you'll see that this is happening after pdfinfo.exe is called on your pdf file. Try running it manually and you'll see what is happening there and if there any errors while running pdfinfo.exe.
I had this error: "The code execution cannot proceed because freetype.dll was not found...". So I just found freetype.dll in my Anaconda path (I used Anaconda to install pdf2image on Win10) and added this path to PATH environment variable, so it would be found. This was the only problem and I've got my images from pdf.
I encountered the same error but I correct my file path after that the issue will be resolved.

Pandas File Not Found Error -- Worked Yesterday

Yesterday I imported an sas file into Pandas, and was able to successfully poke around the data. This morning, I received a file not found error, although I did not move any files.
I triple-checked the path and it was correct. Then I tried placing a copy of the file on my desktop and redirecting read command. Same error. (This is the type of thing that makes you feel crazy.) Any help appreciated.
Unless that you have a folder named Dropbox inside your project directory, I suggest you use the full path of your file:
/home/<username>/Dropbox/Thesis Fall 2017/Data Analysis/epcg17.xpt
OR
~/Dropbox/Thesis Fall 2017/Data Analysis/epcg17.xpt
Both should work.

Python PDFMiner error: "No /Root object! - Is this really a PDF?"

I am getting this error "No /Root object! - Is this really a PDF?" using my MAC computer with Python 2.7 and PDFMiner version 20110515.
The pdf files are not damaged because the same program with the same files works on my PC computer! Also I have tried many pdfs and this error exists for all of them. Any ideas of what I should change in my MAC to not to get this error?
I found the source of the problem:
I had a method to read all the files in a directory and parse them. Turns out that I had one hidden file in that directory that was not a pdf file!
Here is how I fixed the problem:
for filename in os.listdir(INPUT_DIR_NAME):
if filename.endswith('.pdf'):
#do stuff!

Categories

Resources