HOAB

History of a bug

Adding a custom order to woocommerce do not update the post_status

Rédigé par gorki Aucun commentaire

Problem :

Adding a status to Woocommerce.

A lot of resources on internet, for example here

It was not working… I had the status in the list, but when saving the command, the old post status was kept…

1h search….

Solution :

My new order key, especially the post status / order status : wc-clickreserver-ready
To be used in : 

register_post_status( wc-clickreserver-ready, ...

Well, -ready is not a good idea

Perfectly working with :

register_post_status( wc-clickreserver, ...

Lire la suite de Adding a custom order to woocommerce do not update the post_status

Facebook and Woocommerce - resync

Rédigé par gorki Aucun commentaire

Problem :

Times to times, Facebook and Woocommerce lost their synchronization. 

In this case, the solution is to reset everything (if you have on Facebook, only your Woocommerce products !!)

Some information there :

But if your catalog is connected to a shop you can not delete your catalog…

And for any reason, the bulk requests was not working for me : accepted, no error, but still all the products ! 

I used : 

https://graph.facebook.com/v15.0/<my shop>/items_batch

{"allow_upsert": "true", "item_type": "PRODUCT_ITEM", "requests": [
{"method": "DELETE", "data": {"id": "1234"}},
{"method": "DELETE", "data": {"id": "2345"}}
{"method": "DELETE", "data": {"id": "3456"}}
]}

Solution :

So I tried to build the request by myself with a short python file : 


import requests

BASE_URL_FACEBOOK = 'https://graph.facebook.com/v16.0'
BASE_URL_FACEBOOK_BOUTIQUE = f'{BASE_URL_FACEBOOK}/<your shop>'
TOKEN = "yourToken"

# You must initialize logging, otherwise you'll not see debug output.
#logging.basicConfig()
#logging.getLogger().setLevel(logging.DEBUG)

url="/products?bulk_pagination=false&summary=true&limit=1000"
print(f'Calling GET : {url}')
hdr = {'User-Agent': r'Facebook-for-WooCommerce/2.6.27 (WooCommerce/6.8.2; WordPress/5.9.5)', 'Accept':'*/*', 'Content-Type': 'application/json', 'Authorization': f"Bearer {TOKEN}"}
response = requests.get(BASE_URL_FACEBOOK_BOUTIQUE + url, headers=hdr)
if response.status_code == 200 or response.status_code == 201:
    print(f'GET OK')
    products_response = response.json()
    delete_products_requests = list()
    print(products_response['summary']['total_count'])
    for product in products_response['data']:
        id = product['id']
        delete_command = {'method': 'DELETE', 'data': {"id":id}}
        delete_products_requests.append(delete_command)
        
    delete_request = dict()
    delete_request['allow_upsert'] = 'true'
    delete_request['item_type'] = 'PRODUCT_ITEM'
    delete_request['requests'] = delete_products_requests

    url="/items_batch"
    print(json.dumps(delete_request))
    response = requests.post(BASE_URL + url, headers=hdr, data=json.dumps(delete_request))
    print(response.status_code)
    print(response.text)
    response.raise_for_status()
    handles = response.json()['handles']
    print(f'handle = {handles}')

And follow the request with : 

https://graph.facebook.com/v16.0/<shop id>/check_batch_request_status?handle=<myHandle from previous request>

Still no error, but nothing deleted (we can follow the batch request in 

Facebook Business Manager > Catalog > Data Source > Application 

At the end, I found the delete request on a single product (simple by slowest) :

import requests


BASE_URL_FACEBOOK = 'https://graph.facebook.com/v16.0'
BASE_URL_FACEBOOK_BOUTIQUE = f'{BASE_URL_FACEBOOK}/<your shop>'
TOKEN = "yourToken"

url="/products?bulk_pagination=false&summary=true&limit=1000"
print(f'Calling GET : {url}')
hdr = {'User-Agent': r'Facebook-for-WooCommerce/2.6.27 (WooCommerce/6.8.2; WordPress/5.9.5)', 'Accept':'*/*', 'Content-Type': 'application/json', 'Authorization': f"Bearer {TOKEN}"}
response = requests.get(BASE_URL_FACEBOOK_BOUTIQUE + url, headers=hdr)
if response.status_code == 200 or response.status_code == 201:
    print(f'GET OK')
    products_response = response.json()
    products = dict()
    delete_products_requests = list()
    print(products_response['summary']['total_count'])
    for product in products_response['data']:
        id = product['id']
        url=f"/{id}"
        response = requests.delete(BASE_URL_FACEBOOK + url, headers=hdr)
        print(f'{response.status_code} : {response.text}')
        if (response.status_code != 200):
            print(f'Can not delete product {id}')

 

 

 

 

CA Apm Introscope and tracer not executed

Rédigé par gorki Aucun commentaire

Problem :

Silent code :) Configuration was OK, or seems to be, logs was OK but nothing happen.

For a project, I use Broadcom CA APM, formely Introscope, I created a custom Tracer, adding the required configuration but my tracer was not executed. Furthermore, another “standard” tracer was not executed also.

Solution :

Easy steps : 

  • Check the agent logs : ERROR is displayed :
    • [IntroscopeAgent.Agent] Unable to create tracer factories for the following class (library not found): 
  • Put agent logs in VERBOSE mode, I would had the solution directly
    • Same information class not found.
  • But because I everything for remote debug ready, I lost time but learn things
    • My tracer was using the same flag as the standard one : if one tracer can not be created, the whole flag is not enabled.
  • You can trace the classes to check if they are correctly instrumented compared to AutoProbe log. I never, never had a difference hier. If it says it's instrumented, then it is.
  •  

At the end the problem is "class not found" for one of the 2 tracers. So simple

And the class was of course present in the jar file. So it was related to the declaration of this class in the MANIFEST.MF required for CA APM Introscope extension : 

com-wily-Extension-Plugin-XXXX-Name: XXXX Frontend Tracer
com-wily-Extension-Plugin-XXXX-Type: tracer
com-wily-Extension-Plugin-XXXX-Version: 1
com-wily-Extension-Plugin-XXXX-Entry-Point-Class: com.xxx.xxxx.MyTracer

 

Lire la suite de CA Apm Introscope and tracer not executed

Fast browsing and DNS

Rédigé par gorki Aucun commentaire

Problem :

I was surfing on some sites blocked by my DNS provider (no, not yggtorrent. Absolutely not).

So Firefox provide DNS over HTTP with NextDNS, sometimes slower than my provider DNS but well, not so bad.

Then for some reason, I tried to host a local DNS resolver. Well, it WAS slow.

Solution :

Unbound is DNS resolver :

  • easy to install
  • cache request locally, so save a few ms for a lot of requests !
  • and support DNS over https, etc…

Setup is quite simple thanks to internet knowledge :

Installation :
(https://memo-linux.com/debian-installer-le-serveur-dns-unbound/

apt install unbound
cd /var/lib/unbound/ 
wget ftp://ftp.internic.net/domain/named.cache
mv named.cache root.hints && chown unbound:unbound root.hints
mv /etc/unbound/ 
unbound.conf.d/root-auto-trust-anchor-file.conf root-auto-trust-anchor-file.conf.original
mkdir /var/log/unbound
chown unbound: /var/log/unbound
# modify apparmor (see at the end)
systemctl restart unbound

My configuration file :

server:
statistics-interval: 0
extended-statistics: yes
statistics-cumulative: yes
verbosity: 3
interface: 127.0.0.1
port: 53
do-ip4: yes
do-ip6: yes
do-udp: yes
do-tcp: yes
access-control: 127.0.0.0/8 allow ## j'autorise mon serveur
access-control: 0.0.0.0/0 refuse ## j'interdis tout le reste de         l'Internet !
auto-trust-anchor-file: "/var/lib/unbound/root.key"
root-hints: "/var/lib/unbound/root.hints"
hide-identity: yes
hide-version: yes
harden-glue: yes
harden-dnssec-stripped: yes
use-caps-for-id: yes
cache-min-ttl: 3600
cache-max-ttl: 86400
prefetch: yes
num-threads: 6
msg-cache-slabs: 16
rrset-cache-slabs: 16
infra-cache-slabs: 16
key-cache-slabs: 16
rrset-cache-size: 256m
msg-cache-size: 128m
so-rcvbuf: 1m
unwanted-reply-threshold: 10000
do-not-query-localhost: yes
val-clean-additional: yes
#use-syslog: yes
#val-log-level:2 (0: default, nothing, 2: full)
logfile: /var/log/unbound/unbound.log
harden-dnssec-stripped: yes
cache-min-ttl: 3600
cache-max-ttl: 86400
prefetch: yes
prefetch-key: yes

And an additional apparmor configuration to be able to write in a dedicated file :
(https://b4d.sablun.org/blog/2018-09-27-when-unbound-wont-write-logs/)

vim /etc/apparmor.d/local/usr.sbin.unbound

# Site-specific additions and overrides for usr.sbin.unbound.
# For more details, please see /etc/apparmor.d/local/README.
/var/log/unbound/unbound.log rw,

 

Lire la suite de Fast browsing and DNS

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

Fil RSS des articles