私はfreesound APIを使用して、ニューラルネットワークのトレーニングに使用するサウンドクリップを検索およびダウンロードしています。スクリプトが名前に特殊文字を含むファイルを見つけると、エラーが発生し、スクリプトは停止します。特殊文字を含むファイルをダウンロードして検索を続けたいと思います。ここで名前が「/」または「」のファイルをダウンロードするときのエラー
は私のコードです:(APIキーが、中にいた今のためにそれを取り出した)
import freesound, sys,os
client = freesound.FreesoundClient()
client.set_token("API KEY","token")
results = client.text_search(query="dog", page_size=150,
fields="id,name,previews")
for sound in results:
if "/" or "\\" or '.' not in sound.name:
sound.retrieve_preview(".", sound.name+".mp3")
print(sound.name)
エラーコード:
FileNotFoundError: [Errno 2] No such file or directory: '.\\Dog eating Neck
of Goose/Chewing/Breaking Bones.mp3'
if "/"または "\\"または "。" sound.name'ではない:あなたが思っていることはしません。それはちょうど「真実」 –