Closed spaude11 closed 5 months ago
credentials = service_account.Credentials.from_service_account_file('service_account_key.json') drive_service = build('drive', 'v3', credentials=credentials)
def upload_to_google_drive(pdf_filename): file_metadata = { 'name': pdf_filename } media = MediaFileUpload(pdf_filename, mimetype='application/pdf') file = drive_service.files().create(body=file_metadata, media_body=media, fields='id').execute() return file.get('id').
I will work on integrating the google api and setup this is just the basic code that i will use.
credentials = service_account.Credentials.from_service_account_file('service_account_key.json') drive_service = build('drive', 'v3', credentials=credentials)
def upload_to_google_drive(pdf_filename): file_metadata = { 'name': pdf_filename } media = MediaFileUpload(pdf_filename, mimetype='application/pdf') file = drive_service.files().create(body=file_metadata, media_body=media, fields='id').execute() return file.get('id').
I will work on integrating the google api and setup this is just the basic code that i will use.
BadInputError: BadInputError('e77c8dd5b46242f2845404cc0535306b', 'Error in call to API function "files/upload": Your app is not permitted to access this endpoint because it does not have the required scope \'files.content.write\'. The owner of the app can enable the scope for the app using the Permissions tab on the App Console.')
Traceback:
File "/Users/sudeeppaudel/Documents/GitHub/Aquatic-RIG/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
exec(code, module.dict)
File "/Users/sudeeppaudel/Documents/GitHub/Aquatic-RIG/aquaticrig_gui.py", line 42, in
dropbox_token = 'token'
dbx = dropbox.Dropbox(dropbox_token)
def upload_to_dropbox(pdf_filename):
with open(pdf_filename, 'rb') as f:
file_contents = f.read()
dropbox_path = f'/Feedbackfiles/{pdf_filename}' # Specify the path in Dropbox where you want to upload the file
dbx.files_upload(file_contents, dropbox_path, mode=dropbox.files.WriteMode.overwrite)
Description: Met with the error while getting access to the dropbox app from streamlit code. I was working on the feedback reports that are generated. I wanted to store the pdf into a pdf for later reference.
BadInputError: BadInputError('d02f7149882a486d93f493de0057e4bd', 'Error in call to API function "files/upload": Your app is not permitted to access this endpoint because it does not have the required scope \'files.content.write\'. The owner of the app can enable the scope for the app using the Permissions tab on the App Console.')
Expected vs. Actual Behavior Same error after trying for few times after changing the permission on dropbox. I made change on dropbox/developers/apps permission. I was supposed to give permission for files and folder.
Environment: Pycharm IDE, Streamlit Cloud(WebHosting), DropBox(File Storage), Pythov 3.9
This "Your app is not permitted to access this endpoint" error indicates that the access token you're using to make the call does not have the necessary scope needed for calling that particular endpoint. As indicated by the error message in this case, the app would need the "files.metadata.read" scope.
You can add it via the "Permissions" tab on the app's info page on the App Console. Then you can get a new access token with that scope added and use that new access token to make this API call. https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Integrated-creation-folder/td-p/470963
Issue Resolution: Since the Accept cookies was hiding the submit button, I wasn't able to figure out why my change was not updated. When I accepted the cookie and submitted the change through the popup submit button, The change was saved and I regenerated the token. That worked and feedback file I generated was going into the dropbox folder I assigned.
After solving and successfully able to upload it into dropbox.
This "Your app is not permitted to access this endpoint" error indicates that the access token you're using to make the call does not have the necessary scope needed for calling that particular endpoint. As indicated by the error message in this case, the app would need the "files.metadata.read" scope.
You can add it via the "Permissions" tab on the app's info page on the App Console. Then you can get a new access token with that scope added and use that new access token to make this API call. https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Integrated-creation-folder/td-p/470963
This helped me solve the issue The access token is still visible into code, work on hiding the token for security.
This is great and I'm glad we are formatting our issues this way. It makes understanding everyone's progress a lot easier. I'll look at this with you later today.
Description: The objective of this issue was to upload the feedback file name as current date time rather than email address.
Outcome Expective the file named should be in Y_M_D_H_M_S format.
Code Snippets:
def upload_file(self, file_data, file_name, st):
try:
current_time = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
# Construct the new filename with the user's email
new_file_name = f"feedback_report_{current_time}.pdf"
# Upload the file to Dropbox
upload_path = f'/Apps/Feedbackfiles/{new_file_name}'
self.dbx.files_upload(file_data, upload_path, mode=dropbox.files.WriteMode.overwrite)
st.success(f"Feedback PDF '{new_file_name}' uploaded successfully to Dropbox.")
except dropbox.exceptions.ApiError as e:
st.error(f"Error uploading '{file_name}' to Dropbox: {e}")
We will use this ticket for uploading our feedback pdf file into specific dropbox file
The initial plan of using google drive is changed to dropbox.