Hi,
I am currently trying to retrieve a traffic flow map for my area, and I would like to send it to a Discord channel.
The goal is to get the Raster Flow Tile we can see here: https://developer.tomtom.com/content/traffic-api-explorer#/Traffic%20Flow
The issue when I try to retrieve it with the code below, VSCode tells me this:
Command raised an exception: OSError: [WinError 6] Descripteur non valide
I guess it can be translated as : OSError: [WinError 6] The handle is invalid
import os
import json
import sys
import discord
import urllib.request
async def fd_road_map_tomtom():
print('fd_road_map_tomtom')
api_key = os.getenv('TOMTOM_TOKEN')
api_url = f"https://api.tomtom.com/traffic/map/4/tile/flow/absolute/13/[redacted]/[redacted].png?thickness=2&tileSize=512&key={api_key}"
imageRequest = urllib.request.urlopen(api_url)
imageBinary = imageRequest.read()
image = sys.stdout.buffer.write(imageBinary)
file = discord.File(image)
return file
In an other function I have the following, that works well except for the image.
async def trafficFlow(self, ctx):
choosenTime = None
try:
embed = await fd_road_cond_tomtom(choosenTime)
await ctx.send(embed=embed)
except:
print('Les données n\ont pas pu être récupérées.')
else:
tomtomMap = await fd_road_map_tomtom()
await ctx.send('TempsReel.png', file=tomtomMap)
How can this be solved?
Thanks!