HOAB

History of a bug

Wordpress API refuse python rest request

Rédigé par gorki Aucun commentaire

Problem :

Simple test : 

response=requests.get('https://wordpress.site/wp-json/wc/v3/products/attributes',headers=hdr,    
						auth=requests.auth.HTTPBasicAuth('login', 'password'))

But for any reason I received a 403 command.

Same command with curl works : 

curl -vvvv -u login:password https://wordpress.site/wp-json/wc/v3/products/attributes

Well… 

Solution :

Simple, but don't know why.

Default user agent for Python : 

User-Agent: python-requests/2.28.1

Default user agent for curl

user-agent: curl/7.86.0

Well it works with (add a space before the /) : 

User-Agent: python-requests /2.28.1

Still a mystery. Not from python side, maybe from planethoster.com side or wordpress ? One day, I will have time to go further… 

 


 

 

 

Lire la suite de Wordpress API refuse python rest request

Bash and the empty optional arguments on command line

Rédigé par gorki Aucun commentaire

Problem :

Well, I know that having named parameter is better “-file=” etc..

But for a simple task, I wanted to give :

./mycommand arg1 arg2 ‘’ ‘’ arg5

And pass those parameters to a function… 

Solution :

Not so lost in internet but easy to do at the end ! 

So basically, as simple as : 

# Solution OK : use arrau
all_args=("$@");
myfunction "${all_args[@]}"

# Loop over parameters
for i in "${@}"; do
   echo "$i"
done
for i in "${all_args[@]}"; do
   echo "$i"
done

From :

#!/bin/bash

all_args=("$@");

myfunction() {
 arg1=$1
 arg2=$2
 arg3=${3:-'default3'}
 arg4=${4:-'default4'}
 arg5=${5:-'default5'}

 echo "arg1=$arg1"
 echo "arg2=$arg2"
 echo "arg3=$arg3"
 echo "arg4=$arg4"
 echo "arg5=$arg5"
}

echo "--------------- args hard-codede"
myfunction 1 2 "" "" yes
echo "--------------- explode array with quote"
myfunction $(printf ""%s" " "${all_args[@]}")
echo "--------------- working just expand array"
myfunction "${all_args[@]}"

With the following command line : 

./test.sh 1 2 "" "" yes
--------------- args hard-codede
arg1=1
arg2=2
arg3=default3
arg4=default4
arg5=yes
--------------- explode array with quote
arg1="1"
arg2="2"
arg3=""
arg4=""
arg5="yes"
--------------- working just expand array
arg1=1
arg2=2
arg3=default3
arg4=default4
arg5=yes

 

 

 

Fil RSS des articles