Check types_map when using mimetypes on AWS Lambda (Python)

Premise / Environment

AWS Lambda Python environment

Event

I tried to guess_type`` .webp in the Python environment of AWS Lambda.

python


import mimetypes
print(mimetypes.guess_type('.webp'))
# none

It has become none.

python


import mimetypes
print(mimetypes.types_map['.webp'])
# none

webp doesn't exist in types_map, so add it

python


import mimetypes
mimetypes.add_type('image/webp', '.webp')
print(mimetypes.guess_type('.webp'))
# image/webp

Settled.

Summary

The mimetypes dictionary is environment-dependent, so if you can't guess_type or guess_extention, check if the target exists in the dictionary. If it does not exist, it can be added with ʻadd_type`.

Reference) https://note.nkmk.me/python-mimetypes-usage/

Recommended Posts

Check types_map when using mimetypes on AWS Lambda (Python)
Summary if using AWS Lambda (Python)
Run Python on Schedule on AWS Lambda
Addictive points when downloading files using boto on AWS Lambda
A little trick to know when writing a Twilio application using Python on AWS Lambda
[AWS] Using ini files with Lambda [Python]
Install python library on Lambda using [/ tmp]
[Python] Run Headless Chrome on AWS Lambda
Periodically run a python program on AWS Lambda
Python development on Ubuntu on AWS EC2 (using JupyterLab)
How to set layer on Lambda using AWS SAM
Deploy Python3 function with Serverless Framework on AWS Lambda
Support for Python 2.7 runtime on AWS Lambda (as of 2020.1)
Troublesome story when using Python3 with VScode on ubuntu
I want to AWS Lambda with Python on Mac!
A swampy story when using firebase on AWS lamda
Minimum memo when using Python on Mac (pyenv edition)
Minimum notes when using Python on Mac (Homebrew edition)
[Python] Scraping in AWS Lambda
Web scraping using AWS lambda
Broadcast on LINE using python
IP spoof using tor on macOS and check with python
Post images of Papillon regularly on Python + AWS Lambda + Slack
Create API with Python, lambda, API Gateway quickly using AWS SAM
[Python] Allow pip3 packages to be imported on AWS Lambda
How to make AWS Lambda Layers when running selenium × chrome on AWS Lambda
Precautions when using pit in Python
Check the behavior when assigning Python
Introducing Python using pyenv on Ubuntu 20.04
Notes on using MeCab from Python
Preparing python using vscode on ubuntu
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
Write AWS Lambda function in Python
Support when installing pillow on python3.9
Best practice for logging in JSON format on AWS Lambda / Python
Tweet WakaTime Summary using AWS Lambda
Study on Tokyo Rent Using Python (3-2)
Notes on installing Python using PyEnv
Using Lambda with AWS Amplify with Go
[Python] Be careful when using print
I compared Node.js and Python in creating thumbnails using AWS Lambda
Check python code styles using pep8
Notes on using rstrip with python.
If you are having trouble with timeouts when implementing Slack's SlashCommand in Python on AWS Lambda
A note on using tab completion when running Python interactively on Windows
Install Python on CentOS using Pyenv
Study on Tokyo Rent Using Python (3-3)
Notify HipChat with AWS Lambda (Python)
Error log output method when using Bottle framework on GAE / Python
Precautions when using phantomjs from python
[Python] I wrote a REST API using AWS API Gateway and Lambda.
When using MeCab with virtualenv python
Install Python on CentOS using pyenv
Precautions when using six with Python 2.5
[VS Code] ~ Tips when using python ~
When using regular expressions in Python
ImportError when trying to use gcloud package with AWS Lambda Python version
Settings when using Python 3 requests and Beautiful Soup with crostini on Chromebook
Modules cannot be imported in Python on EC2 run from AWS Lambda
Notes for using OpenCV on Windows10 Python 3.8.3.
Execute Python code on C ++ (using Boost.Python)