We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
mukul04
6 years agoNew member | Level 2
Re: stone_validators.ValidationError
Hi Greg,
def insert_data():
has_more = True
cursor = cnxn.cursor()
while has_more:
if cursor is None:
entries = dbx.files_list_folder(Dropbox_file, limit=2000).entries
else:
entries = dbx.files_list_folder_continue(cursor)
for entry in entries:
...
cursor = entries.cursor
# Repeat only if there's more to do
has_more = entries.has_more
I'm getting an error with the message
dropbox.stone_validators.ValidationError: '<pyodbc.Cursor object at 0x000002831027A8B0>' expected to be a string, got Cursor
Can you help me fix this? I'm trying to read more than 2000 files in a single dropbox folder..
2 Replies
- Greg-DB6 years ago
Dropbox Community Moderator
When using files_list_folder_continue, the cursor you pass in should be the last cursor returned by files_list_folder or files_list_folder_continue. You seem to be correctly saving that cursor via 'cursor = entries.cursor', however you overwrite it via 'cursor = cnxn.cursor()'.
I don't see where 'cnxn' is defined, but based on the error output you seem to be passing in a "pyodbc.Cursor" object, which seems to be an object from this unrelated pyodbc library. You'll need to fix your code to pass in the Dropbox cursor string, not a pyodbc.Cursor.
- mukul046 years agoNew member | Level 2
Thanks Greg, I tried doing this and it seems to work! Might be useful as a template while reading more number of files and inseting them to a MySQL dsatabase.
#Connect to the SQL databaseimport pyodbcimport osimport jsonimport globfrom pathlib import Pathimport datetime as dtimport stringimport dropbox#Connect to the DBcnxn = pyodbc.connect('Driver={SQL Server};Server=;Database=;Trusted_Connection=yes;')print("Connection established")cnxn.timeout = 60cnxn.autocommit = Truecursor = cnxn.cursor()dbx = dropbox.Dropbox("")result = dbx.files_list_folder("", recursive=True, include_deleted=False, include_media_info=False)def process_entries(entries):for entry in entries:if isinstance(entry, dropbox.files.FileMetadata):#print(entry.name)md, res = dbx.files_download(entry.path_lower)json_obj = json.loads(res.content)al_data = json.dumps(json_obj)...#Insert values into the DBcursor.execute("INSERT INTO dbo.audiolink_table_1 (...)process_entries(result.entries)# Check if there are more files in the folderwhile result.has_more:result = dbx.files_list_folder_continue(result.cursor)process_entries(result.entries)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!