Here is a minimal sample code. It results in an error:
Erreur : 405 {"stat":"fail","err":405,"message":"The image (file) is missing"}
A session is created successfully. Then we try to send an image after a check that the path is OK for the image. But it fails.
import requests
import configPiwigo as cp
piwigo_base_url = "https://galleries.grains-de-culture.fr/ws.php"
url = piwigo_base_url+"?format=json&method=pwg.session.login"
auth_data = {
"username": cp.configPiwigo["login"],
"password": cp.configPiwigo["pass"],
}
session = requests.Session() # Crée une session persistante
response = session.post(url, data=auth_data)
if response.ok and response.json().get("stat") == "ok":
print("Connexion réussie!")
image_path = "image.jpg"
# check if the image is findable
with open(image_path,"r") as fimage:
print("image trouvée: ", image_path)
# send the image
payload = {
"image": image_path,
"method": "pwg.images.addSimple",
"category": 15,
"name": "Test",
}
# Envoi de la requête avec authentification
response_image = session.post(
piwigo_base_url+"?format=json&method=pwg.images.addSimple",
data=payload
)
# Vérification du succès de l'opération
if response_image.status_code == 200:
print("image uploaded in my piwigo, category 15")
else:
print("Erreur :", response_image.status_code, response_image.text)
Here is a minimal sample code. It results in an error:
Erreur : 405 {"stat":"fail","err":405,"message":"The image (file) is missing"}
A session is created successfully. Then we try to send an image after a check that the path is OK for the image. But it fails.
```
import requests
import configPiwigo as cp
piwigo_base_url = "https://galleries.grains-de-culture.fr/ws.php"
url = piwigo_base_url+"?format=json&method=pwg.session.login"
auth_data = {
"username": cp.configPiwigo["login"],
"password": cp.configPiwigo["pass"],
}
session = requests.Session() # Crée une session persistante
response = session.post(url, data=auth_data)
if response.ok and response.json().get("stat") == "ok":
print("Connexion réussie!")
image_path = "image.jpg"
# check if the image is findable
with open(image_path,"r") as fimage:
print("image trouvée: ", image_path)
# send the image
payload = {
"image": image_path,
"method": "pwg.images.addSimple",
"category": 15,
"name": "Test",
}
# Envoi de la requête avec authentification
response_image = session.post(
piwigo_base_url+"?format=json&method=pwg.images.addSimple",
data=payload
)
# Vérification du succès de l'opération
if response_image.status_code == 200:
print("image uploaded in my piwigo, category 15")
else:
print("Erreur :", response_image.status_code, response_image.text)
```
<!-- github-sync-id:2655911779 -->
In the documentation https://github.com/Piwigo/Piwigo/wiki/pwg.images.addSimple, the image parameter seems to be a parameter like the others and must contain a path to a file. In reality, it must be the image data in the post request query attachment.
In the documentation https://github.com/Piwigo/Piwigo/wiki/pwg.images.addSimple, the image parameter seems to be a parameter like the others and must contain a path to a file. In reality, it must be the image data in the post request query attachment.
<!-- github-comment-id:2476484622 -->
This can be illustrated with the folllowing extract
with open(image_path, 'rb') as img_file:
files = {'image': (image_path, img_file, 'image/jpeg')}
response = session.post(
piwigo_base_url+"?format=json&method=pwg.images.addSimple",
data=payload,
files=files
)
This can be illustrated with the folllowing extract
```
with open(image_path, 'rb') as img_file:
files = {'image': (image_path, img_file, 'image/jpeg')}
response = session.post(
piwigo_base_url+"?format=json&method=pwg.images.addSimple",
data=payload,
files=files
)
```
<!-- github-comment-id:2477402259 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Here is a minimal sample code. It results in an error:
Erreur : 405 {"stat":"fail","err":405,"message":"The image (file) is missing"}
A session is created successfully. Then we try to send an image after a check that the path is OK for the image. But it fails.
In the documentation https://github.com/Piwigo/Piwigo/wiki/pwg.images.addSimple, the image parameter seems to be a parameter like the others and must contain a path to a file. In reality, it must be the image data in the post request query attachment.
This can be illustrated with the folllowing extract