GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Disallowed `NaN` and `Infinity` values in JSONs sent to the Apify API by fnesveda · Pull Request #87 · apify/apify-client-python

Conversation

@fnesveda

@fnesveda fnesveda commented Dec 1, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

If you tried to push an item which contained a NaN to a dataset, it would return an error from the Apify API, that the JSON you sent to it is invalid.

>>> client.dataset('~nan-testing-dataset').push_items([{ 'a': float('NaN')}])
ApifyApiError: Cannot parse POST payload as JSON: Unexpected token N in JSON at position 7

That is because in Python, by default, json.dumps() stringifies NaN and Infinity values. This is against the JSON standard, and JSON.parse on the API fails to parse the value.

This fixes it by adding the allow_nan=False parameter to json.dumps(), so that the error is caught before sending the invalid JSON to the API, and throws an error early.

>>> client.dataset('~nan-testing-dataset').push_items([{ 'a': float('NaN')}])
ValueError: Out of range float values are not JSON compliant: nan

By the way, when fixing this, I made my first fix to CPython: python/cpython#99926

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fnesveda
Disallowed NaN and Infinity values in JSONs sent to the Apify API
ed7efa0
@fnesveda fnesveda added bug Something isn't working. adhoc Ad-hoc unplanned task added during the sprint. labels Dec 1, 2022
@fnesveda fnesveda added this to the 52nd sprint - Platform team milestone Dec 1, 2022
@fnesveda
fnesveda requested review from Equidem and jirimoravcik December 1, 2022 14:34
@fnesveda fnesveda self-assigned this Dec 1, 2022
@github-actions github-actions Bot added the t-core-services Issues with this label are in the ownership of the core services team. label Dec 1, 2022
jirimoravcik
jirimoravcik approved these changes Dec 2, 2022
View reviewed changes
@fnesveda
fnesveda merged commit dbf483f into master Dec 6, 2022
@fnesveda
fnesveda deleted the fix/disallow-nans branch December 6, 2022 15:16
@fnesveda fnesveda added the validated Issues that are resolved and their solutions fulfill the acceptance criteria. label May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jirimoravcik jirimoravcik jirimoravcik approved these changes
@Equidem Equidem Awaiting requested review from Equidem

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@fnesveda fnesveda

Labels

adhoc Ad-hoc unplanned task added during the sprint. bug Something isn't working. t-core-services Issues with this label are in the ownership of the core services team. validated Issues that are resolved and their solutions fulfill the acceptance criteria.

Projects

None yet

Milestone

52nd sprint - Platform team

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@fnesveda @jirimoravcik
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.