No idea where this file id error is coming from
I'm trying to code some Python to get around Box's crippled search functionality, and I'm getting a bizarre error that I can't seem to track down. I'm hoping someone can offer insight.
Using either the boxsdk package for Python, or directly querying using the Python requests library, I'm getting errors about invalid file ids that are not what I'm passing in. Something somewhere is mangling them by prepending "f_" to the id string, which is enough to botch the operation.
It seems to especially affect attempts to restore items from the trash (as per the Box API docs).
Version using boxsdk
oauth = boxsdk.OAuth2(CLIENT_ID, CLIENT_SECRET, access_token=DEV_TOKEN) client = boxsdk.DevelopmentClient(oauth) authheaders = {'Authorization': 'Bearer {}'.format(client.auth.access_token) } thefile = client.file(file_id='12345678') #file id obfuscated in this example restored = client.trash().restore_item(thefile) BoxAPIException: Message: Not Found Status: 404 Code: not_found Request ID: prk91cfyt0jxy0vy Headers: {'Date': 'Wed, 02 Jan 2019 22:52:28 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=31536000', 'Cache-Control': 'no-cache, no-store', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'BOX-REQUEST-ID': '0qtqf38b2ejacpt9i4gv962e55b', 'Age': '0'} URL: https://api.box.com/2.0/files/12345678 Method: POST Context Info: {'errors': [{'reason': 'invalid_parameter', 'name': 'items', 'message': "Invalid value 'f_12345678'. 'items' with value 'f_12345678' not found"}]}
Version using requests library:
thefile.object_id # '12345678' thefile.get_url() # 'https://api.box.com/2.0/files/12345678' resp = requests.post('https://api.box.com/2.0/files/12345678', headers=authheaders) resp.json() {'type': 'error', 'status': 404, 'code': 'not_found', 'context_info': {'errors': [{'reason': 'invalid_parameter', 'name': 'items', 'message': "Invalid value 'f_12345678'. 'items' with value 'f_12345678' not found"}]}, 'help_url': 'http://developers.box.com/docs/#errors', 'message': 'Not Found', 'request_id': 'n6ez8lfyt0pj9ix8'}
I can't tell where that mangled string is coming from; I don't think it's something I'm doing. I've reproduced the issue on 2 different machines, both using Python 3.6. I'd appreciate any insight. It's driving me a little nuts.
Please sign in to leave a comment.
Comments
1 comment