pyinaturalist: TypeError when using local_photos parameter in create_observation(): Object of type BytesIO is not JSON serializable

Hi folks. I’ve been playing with pyinaturalist with the intention of using it to streamline the upload of a database of observation records and associated photographs.

However, I’ve run into a problem. The following works brilliantly:

response = create_observation(
    species_guess='Mallard',
    observed_on_string='2020-05-03',
    time_zone='Brussels',
    description='Test observation, will be deleted shortly',
    tag_list='test, API',
    latitude=-53.186881, 
    longitude=-134.823015,
    positional_accuracy=50, # GPS accuracy in meters
    access_token=token,
)

new_observation_id = response[0]['id']

add_photo_to_observation(
    new_observation_id,
    access_token=token,
    photo='H:\My Documents\iNaturalist\inaturalistTest3.jpg',
)

However, when I try to combine it all into a single step using the local_photos parameter I get an error:

response = create_observation(
    species_guess='Mallard',
    observed_on_string='2020-05-03',
    time_zone='Brussels',
    description='Test observation, will be deleted shortly',
    tag_list='test, API',
    latitude=-53.186881, 
    longitude=-134.823015,
    positional_accuracy=50, # GPS accuracy in meters
    access_token=token,
    local_photos='H:\My Documents\iNaturalist\inaturalistTest3.jpg',
)

TypeError: Object of type BytesIO is not JSON serializable

Unfortunately, I’m not yet competent enough with python to know whether this is a problem on my end, or if it’s an issue deeper in the package. In either case, your advice and guidance would be much appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Great work JWCook! I have installed the pre-release build, and it works as desired.

Many thanks!