Skip to content

AttributeError: 'NoneType' object has no attribute 'startswith' in media_upload (api.py) #2199

Description

@ken-vat

Summary

This is a bizarre error for a simple jpg type file (https://cdn1.epicgames.com/spt-assets/4c326848c77b4d9795b9262b789b6145/moonfire-a-seekers-saga-vao3b.jpg). Insta and Fb dont have this issue in posting.

Reproduction Steps

My script calls .media_upload(file_name) with .jpg type file (https://cdn1.epicgames.com/spt-assets/4c326848c77b4d9795b9262b789b6145/moonfire-a-seekers-saga-vao3b.jpg).
Code:
media = _client_v1.media_upload(filename=new_product_image_path)

Error:
File "/usr/local/lib/python3.10/site-packages/tweepy/api.py", line 3396, in media_upload
if chunked or file_type.startswith('video/'):
AttributeError: 'NoneType' object has no attribute 'startswith'

Minimal Reproducible Example

My script calls <client>.media_upload(file_name) with .jpg type file (https://cdn1.epicgames.com/spt-assets/4c326848c77b4d9795b9262b789b6145/moonfire-a-seekers-saga-vao3b.jpg). 
Code:
media = _client_v1.media_upload(filename=new_product_image_path)

Error:
  File "/usr/local/lib/python3.10/site-packages/tweepy/api.py", line 3396, in media_upload
    if chunked or file_type.startswith('video/'):
AttributeError: 'NoneType' object has no attribute 'startswith'

Expected Results

return "media" type object

Actual Results

AttributeError: 'NoneType' object has no attribute 'startswith'

Twitter API Access Plan

Free

Tweepy Version

v1.1 for media_upload. No media_upload yet in v2.0

Checklist

  • I have searched for duplicate issues.
  • If applicable, I have shown the entire traceback.
  • If applicable, I have removed any visible credentials from my code and/or screenshots.

Additional Context

    if file is not None:
        location = file.tell()
        h = file.read(32)
        file.seek(location)
    file_type = imghdr.what(filename, h=h)
    if file_type is not None:
        file_type = 'image/' + file_type
    else:
        file_type = mimetypes.guess_type(filename)[0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Unconfirmed BugThis is a bug report that has not been triaged yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions