Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3709

Tentative de transcription d'une ligne de commande « Curl » à l'aide de « urllib3 ».

Path csiph.com!pasdenom.info!usenet-fr.net!agneau.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!cleanfeed1-a.proxad.net!nnrp1-1.free.fr!not-for-mail
From Valrik <nospam@valrik.invalid>
Newsgroups fr.comp.lang.python
Subject Tentative de transcription d'une ligne de commande « Curl » à l'aide de « urllib3 ».
Date Thu, 20 Jan 2022 01:20:34 +0100
Message-ID <87lezbntpp.fsf@s02.forall> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock sha1:MUwKuDaKadDoS5mm0bCOQfX7Myw=
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding quoted-printable
Lines 73
Organization Guest of ProXad - France
NNTP-Posting-Date 20 Jan 2022 01:20:34 CET
NNTP-Posting-Host 91.172.153.64
X-Trace 1642638034 news-4.free.fr 8913 91.172.153.64:53926
X-Complaints-To abuse@proxad.net
Xref csiph.com fr.comp.lang.python:3709

Show key headers only | View raw


Bonjour à tous,

je suis grand débutant en Python, Json et Graphql. Mes questions, donc,
pourront peut-être vous paraître naïves.

Je tente actuellement de programmer une petite application en lignes de
commandes (CLI) permettant de visualiser la grille des programmes de
Radio France. Openapi de Radio France, m'a fourni une clé afin de
pouvoir me connecter sur leur serveur Graphql.

Il existe également un « terrain de jeux » sur
https://openapi.radiofrance.fr/ avec des exemples. Il y a possibilité de
copier la requête et cela donne pour l'un des exemples :

curl 'https://openapi.radiofrance.fr/v1/graphql?x-token=clé_que_je_ne_peux_pas_rendre_publique_pour_l'instant' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: https://openapi.radiofrance.fr' --data-binary '{"query":"{\n  diffusionsOfShowByUrl(url: \"https://www.franceculture.fr/emissions/fictions-theatre-et-cie\", first: 10) {\n\t edges {\n      cursor\n      node {\n          id\n          title\n          url\n          published_date\n          podcastEpisode {\n            url\n            title\n          }\n      }\n    }\n  }\n}"}' --compressed

À noter que cela fonctionne correctement dans un terminal.

J'ai tenté tant bien que mal de transcrire cette commande en Python et
voilà ce que cela donne :

import urllib3

data_binary='{"query":"{\n  diffusionsOfShowByUrl(url: \"https://www.franceculture.fr/emissions/fictions-theatre-et-cie\", first: 10) {\n\t edges {\n      cursor\n      node {\n          id\n          title\n          url\n          published_date\n          podcastEpisode {\n            url\n            title\n          }\n      }\n    }\n  }\n}"}'

http = urllib3.PoolManager()

r = http.request(
    'GET',
    'https://openapi.radiofrance.fr/v1/graphql?x-token=clé_que_je_ne_peux_pas_rendre_publique_pour_l'instant',
    headers={
        'Accept-Encoding': 'gzip, deflate, br',
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Connection': 'keep-alive',
        'DNT': '1',  # Obsolète.
        'Origin': 'https://openapi.radiofrance.fr'
    }
)

print(r.data)

Cela me retourne :
b'Must provide query string.'

Ce qui est plutôt logique puisque il n'y a aucune requête Graphql !  ;-)

J'ai tenté de trouver la transcription correcte de celle-ci sur
Internet, épluché la page Man de Curl, coder « à l'arrache »… rien n'y
fait !

Je n'est également rien trouvé sur « --compressed », mais je dois avouer
que j'ai fait beaucoup moins de recherche.

Et bien voilà, je pense avoir fait le tour de la question. Il ne me
reste plus qu'à vous remercier de votre attention.  :-)

Back to fr.comp.lang.python | Previous | NextNext in thread | Find similar


Thread

Tentative de transcription d'une ligne de commande « Curl » à l'aide de « urllib3 ». Valrik <nospam@valrik.invalid> - 2022-01-20 01:20 +0100
  Re: Tentative de transcription d'une ligne de commande « Curl » à l'aide de « urllib3 ». Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-01-20 18:25 +0100
    Re: Tentative de transcription d'une ligne de commande « Curl » à l'aide de « urllib3 ». Valrik <nospam@valrik.invalid> - 2022-01-21 01:21 +0100
      Re: Tentative de transcription d'une ligne de commande « Curl » à l'aide de « urllib3 ». Valrik <nospam@valrik.invalid> - 2022-01-21 03:21 +0100
        Re: Tentative de transcription d'une ligne de commande « Curl » à l'aide de « urllib3 ». Valrik <nospam@valrik.invalid> - 2022-02-05 00:28 +0100

csiph-web