I tried upload photo to flickr with the API Python but I get this error:
err code="100" msg="Invalid API Key (Key has invalid format)"
I'm supposed Flickr authenticated because simpler ones I call functions that also require authentication as flickr.photos.getInfo, flickr.photos.getPerms or flickr.photos.geo.setLocation and return results without problem.
This is my code:
import flickrapi
import csv
import requests
api_key = 'xxxxxxx'
api_secret = 'zzzzzzzz'
flickr = flickrapi.FlickrAPI(api_key, api_secret)
flickr.authenticate_via_browser(perms='delete')
def uploadPhoto(path_photo, title, description, tags):
result=False;
with open(path_photo, 'rb') as f:
photo = {'file': f}
try:
result = requests.post('https://up.flickr.com/services/upload/', data = {'photo':'photo', 'title':'title', 'description':'description', 'tags':'tags'})
print(result.text)
except Exception as error:
print('Upload photo', error, '--- o --- titulo malo -> ', title)
return result
with open('/home/labsis06/djandoprojects/generales.csv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter=';')
#for row in spamreader:
try:
path_photo = '/home/labsis06/djandoprojects/Fotos_flickr/Phaeophytas4024/4024.55.165_C_sinuosa_000_01_600_778x820.jpg'
title = 'C_sinuosa_000_01_600_778x820.jpg'
description = 'Nombre Especie: Colpomenia sinuosa (Mertens ex Roth) Derbès y Solier . Descripción: Sartedemie'
tags = 'OCHROPHYTA'+','+'Phaeophyceae'+','+'Scytosiphonaceae'+','+'Colpomenia'
print("Ingresando fotos: result: "+str(uploadPhoto(path_photo, title, description, tags)))
except Exception as error:
print('Abiendo csv', error)
I have a group of pictures (approximately 3000 pictures) and I want to upload a csv file, but to prove what I'm doing with a static value.
Any idea what is the problem?
Appreciate your help.
Regards
I'm guessing you are using the API from https://stuvel.eu/flickrapi ?
If so, the docs say the API key and secret need to be a unicode string ( https://stuvel.eu/flickrapi-doc/2-calling.html ), so you'll need to prefix your literals with a 'u'.
ie
api_key = u'xxxxxxx'
api_secret = u'xxxxxxx'
If you are using https://stuvel.eu/flickrapi then you should be using flickr.upload .
If not then need to sign the call which uploads the photo, and I can't see that you actually upload the photo data as you are quoting photo here:
result = requests.post('https://up.flickr.com/services/upload/', data = {'photo':'photo', 'title':'title', 'description':'description', 'tags':'tags'})
See uploader.py for a python example and the Flickr documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.