LargeFileUploadTask fails: AttributeError: 'NoneType' object has no attribute 'create_from_discriminator_value'
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne mit msgraph_core/tasks/large_file_upload.py, insbesondere mit last_chunk, und folge der in der Traceback gezeigten Parsing-Logik für die Antwort des Request-Adapters. Reproduziere das Problem mit dem bereitgestellten Code und einer Datei, die größer als 5 MB ist; fertig ist es, wenn der Upload ohne den NoneType-Parsing-Fehler abgeschlossen wird und sein Ergebnis zurückgibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
I am using LargeFileUploadTask to upload files to a sharepoint directory using the following code.
The file is uploaded in visible in the sharepoint, but the code returns an error.
Code:
from azure.identity.aio import ClientSecretCredential # async credentials only
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
import os
from msgraph import GraphServiceClient
from msgraph_core.tasks.large_file_upload import LargeFileUploadTask, LargeFileUploadSession
import asyncio
from msgraph.generated.drives.item.items.item.create_upload_session.create_upload_session_post_request_body import CreateUploadSessionPostRequestBody
from msgraph.generated.models.drive_item_uploadable_properties import DriveItemUploadableProperties
from datetime import datetime, timedelta, timezone
from kiota_abstractions.api_error import APIError
# Replace these with your app and tenant information
client_id = ''
client_secret = ''
tenant_id = ''
site_id = ''
drive_id = ''
folder_path = '' # Local path of the file to upload
file_name = ''
scopes = ['https://graph.microsoft.com/.default']
credential = ClientSecretCredential(
tenant_id,
client_id,
client_secret)
# Initialize the Graph client
graph_client = GraphServiceClient(credential, scopes)
async def upload_large_file_to_sharepoint(graph_client, site_id, drive_id, folder_path, file_path, file_name):
try:
# Create the upload session URL path
file = open(f"{folder_path}/{file_name}",'rb')
uploadable_properties = DriveItemUploadableProperties(
additional_data={'@microsoft.graph.conflictBehavior': 'replace'}
)
upload_session_request_body = CreateUploadSessionPostRequestBody(
item=uploadable_properties)
try:
upload_session = await graph_client.drives.by_drive_id(drive_id).items.by_drive_item_id('root:/export/out_seasons2.csv:').create_upload_session.post(upload_session_request_body)
except APIError as ex:
print(f"Error creating upload session: {ex}")
# to be used for large file uploads
large_file_upload_session = LargeFileUploadSession(
upload_url=upload_session.upload_url,
expiration_date_time=datetime.now(timezone.utc) + timedelta(days=1),
additional_data=upload_session.additional_data,
is_cancelled=False,
next_expected_ranges=upload_session.next_expected_ranges
)
task = LargeFileUploadTask(
large_file_upload_session,
graph_client.request_adapter,
file)
total_length = os.path.getsize(f"{folder_path}/{file_name}")
# Upload the file
# The callback
def progress_callback(uploaded_byte_range: tuple[int, int]):
print(f"Uploaded {int(uploaded_byte_range[0])/1024/1024:.2f} MegaBytes of {int(total_length)/1024/1024:.2f} MegaBytes\n")
try:
upload_result = await task.upload(progress_callback)
print(f"Upload complete {upload_result}")
except APIError as ex:
print(f"Error uploading: {ex.message} - {ex.response_status_code}")
except APIError as e:
print(f"Error: {e}")
# Run the async upload function
asyncio.run(upload_large_file_to_sharepoint(graph_client, site_id, drive_id, folder_path, folder_path, file_name))
Error:
Traceback (most recent call last):
File "/Users/timwiethoff/Documents/dev/spielwiese_python/sharepoint-func copy.py", line 72, in <module>
asyncio.run(upload_large_file_to_sharepoint(graph_client, site_id, drive_id, folder_path, folder_path, file_name))
File "/opt/homebrew/anaconda3/envs/spielwiese/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/opt/homebrew/anaconda3/envs/spielwiese/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/anaconda3/envs/spielwiese/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/timwiethoff/Documents/dev/spielwiese_python/sharepoint-func copy.py", line 65, in upload_large_file_to_sharepoint
upload_result = await task.upload(progress_callback)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/anaconda3/envs/spielwiese/lib/python3.12/site-packages/msgraph_core/tasks/large_file_upload.py", line 110, in upload
response = await self.last_chunk(self.stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/anaconda3/envs/spielwiese/lib/python3.12/site-packages/msgraph_core/tasks/large_file_upload.py", line 220, in last_chunk
return await self.request_adapter.send_async(info, parsable_factory, error_map)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/anaconda3/envs/spielwiese/lib/python3.12/site-packages/kiota_http/httpx_request_adapter.py", line 190, in send_async
value = root_node.get_object_value(parsable_factory)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/anaconda3/envs/spielwiese/lib/python3.12/site-packages/kiota_serialization_json/json_parse_node.py", line 219, in get_object_value
result = factory.create_from_discriminator_value(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'create_from_discriminator_value'
Expected behavior
Dont generate an error, because the file is uploaded successfully.
How to reproduce
Use my code snippet and upload a file larger than 5 mb.
SDK Version
1.1.6
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
OS: MacOS Sequoia 15.0.1
ARM
### Other information
_No response_
- Vorherrschende Sprache
- Python
- Sterne
- 288
- Forks
- 53
- Ø Merge
- 8 Std. 10 Min.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoftgraph/msgraph-sdk-python-core
-
BatchRequestItem keeps the absolute URL, and set_url() only matches //v1.0/Evtl. vergeben @HardMax71 hat das vor 30 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
microsoftgraph/msgraph-sdk-python-core#1116 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Logging to root loggerOffenstatus:waiting-for-triage type:bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
microsoftgraph/msgraph-sdk-python-core#1078 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
status:waiting-for-triage type:bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
microsoftgraph/msgraph-sdk-python-core#1030 · 3 Kommentare · 4 Reaktionen ·
Maintainer antworten meist innerhalb von 2 Tagen
-
AsyncGraphTransport silently skips the entire middleware pipeline (URL-replace, retry, redirect) with microsoft-kiota-http>=1.13.0Evtl. vergeben @rksharma-owg hat das vor 12 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
microsoftgraph/msgraph-sdk-python-core#1128 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
status:waiting-for-triage type:feature
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
microsoftgraph/msgraph-sdk-python-core#1115 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in microsoftgraph/msgraph-sdk-python-core
Ähnliche Issues
-
enhancement P2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Toloka/tolokaforge#1776 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
TencentCloud/Octop#1622 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
-
Rust: `const _` gets its file's node ID, so the file node is relabelled `_` and gains a self-loopOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Graphify-Labs/graphify#4064 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen