Skip to content

invalid literal for int() with base 10: '' when using LargeFileUploadTask #1631

Backlog
microsoftgraph/msgraph-sdk-python-core
#1172

Description

@Brandhor

Describe the bug

I'm having some difficulties uploading a large attachment to an email because there's pretty much no documentation but from what I've read in this repo I've tried something like this

Expected behavior

I expect it to upload the file

How to reproduce

request_body = CreateUploadSessionPostRequestBody(
    attachment_item=AttachmentItem(
        attachment_type=AttachmentType.File,
        name=x.filename,
        size=x.size,
        content_type=x.content_type,
    ),
)

upload_session = await u.messages.by_message_id(msg.id).attachments.create_upload_session.post(request_body)


large_file_upload_session = LargeFileUploadSession(
    upload_url=upload_session.upload_url,
    expiration_date_time=datetime.datetime.now(datetime.UTC) + datetime.timedelta(days=1),
    additional_data=upload_session.additional_data,
    is_cancelled=False,
    next_expected_ranges=upload_session.next_expected_ranges
)

file_upload_task = LargeFileUploadTask(
    upload_session=large_file_upload_session,
    request_adapter=GraphRequestAdapter(AnonymousAuthenticationProvider()), #using client.request_adapter sends the bearer auth header which results in a 401 error
    stream=io.BytesIO(x.content),
    parsable_factory=FileAttachment
)

await file_upload_task.upload()

SDK Version

1.65.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

but I'm getting this error

msgraph_core\tasks\large_file_upload.py:203, in LargeFileUploadTask.last_chunk(self, file, range_start, range_end, parsable_factory)
    201 range_parts = self.next_range.split('-') if self.next_range else ['-']
    202 start = int(range_parts[0])
--> 203 end = int(range_parts[1]) if len(range_parts) > 1 else 0
    204 if start == 0 and end == 0:
    205     chunk_data = file.read(self.max_chunk_size)

ValueError: invalid literal for int() with base 10: ''

I've tried to debug it and self.next_range is something like "535313-" so when it's splitted range_parts becomes ["535313", ""]

Configuration

No response

Other information

No response

Activity

  1. added
    status:waiting-for-triage
    type:bug
    on Nov 24, 2026
  2. nabeleon94 commented on Nov 28, 2026

    @nabeleon94

    The int('') error comes from LargeFileUploadTask.upload() in msgraph-sdk-python-core. After each chunk it appends "-" to the service's nextExpectedRanges value ("535313" becomes "535313-"), and next_chunk()/last_chunk() then parse the empty end. I opened a fix with tests here: microsoftgraph/msgraph-sdk-python-core#1172. It also stops the final chunk from being sent twice, which is the 400 in #1067.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triagetype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions