GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mimetypes.guess_extension : AttributeError: 'NoneType' object has no attribute 'lower' · Issue #96264 · python/cpython

mimetypes.guess_extension : AttributeError: 'NoneType' object has no attribute 'lower' #96264

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
mimetypes.guess_extension : AttributeError: 'NoneType' object has no attribute 'lower'#96264
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@HGStyle
HGStyle
opened on Aug 25, 2022
Issue body actions

Hi, when i call the function "guess_extension" from the mimetypes module, i get an error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/hg/Bureau/ezConverter/module.py", line 14, in getRealExtension
    currentext = mime.guess_extension(x[0])
  File "/usr/lib/python3.9/mimetypes.py", line 326, in guess_extension
    return _db.guess_extension(type, strict)
  File "/usr/lib/python3.9/mimetypes.py", line 192, in guess_extension
    extensions = self.guess_all_extensions(type, strict)
  File "/usr/lib/python3.9/mimetypes.py", line 171, in guess_all_extensions
    type = type.lower()
AttributeError: 'NoneType' object has no attribute 'lower'

I dont think it's my code. But it is here :

import mimetypes as mime
def getRealExtension(filename):
    x = mime.guess_type(filename)
    currentext = mime.guess_extension(x[0])
# I import it to the shell and call the function.

Thanks in advance !

Activity

  1. HGStyle
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Aug 25, 2022
  2. ericvsmith commented on Aug 25, 2022

    @ericvsmith
    ericvsmith
    on Aug 25, 2022
    Member
    More actions

    Your filename Is probably None. If you can provide a small, complete example that we can run then we can take a look at it, otherwise not much we can do.

    Reacted by Zachary Ware
  3. zware
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Aug 25, 2022
  4. zware commented on Aug 25, 2022

    @zware
    zware
    on Aug 25, 2022
    Member
    More actions

    mimetypes.guess_type is documented to return None for the type portion of its return tuple when the type cannot be guessed, and mimetypes.guess_all_extensions (and, thereby, mimetypes.guess_extension) expects a str type argument. There's no bug in the mimetypes module here.

    You could work around this by using mimetypes.guess_extension(mimetypes.guess_type(filename)[0] or '').

  5. zware
    closed this as not plannedon Aug 25, 2022
  6. zware
    removed
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Aug 25, 2022
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

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.