Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Want to release a contrib.... but it does not work


Guest

Recommended Posts

Posted

So i had this thing that worked before, but after the hoster upgraded php for some reason it does not work

 

 

What is it?

 

Its a set of php files placed in the root folder that are able to list pending orders, list the order data, change the status....

 

 

then on a raspberry pi i have a python script (not made by me) that first calls the first files that list all order with the status of 1 (pending)

it then prints out each order...(on a thermal printer in my case)

then changes them to processing and lets the customer know

each time at midnight it changes them to finished

 

it was made for a pizza delivery that does not have time to check for new orders, nor have time to go and change the status

and the customer would not need to know the day after that they ate a pizza...

 

 

until the hoster upgraded their php it has worked....

 

the php files on the server does still list order numbers when i call them in a browser

 

but for some strange reason the python script now see's the order number+status as a float and not 2 numbers with a space between... 

 

i want to release this but not before its working...

 

anyone that can help me with that?

 

python script is here: https://github.com/boelle/OSCommerceClient/blob/master/OSCommerceClient.py

 

the files for the root folder is here: https://github.com/boelle/OSCommerceClient/tree/master/php-files

 

the project initial started out on the arduino platoform but found out a pi was better suited...

 

when i run the py script i get this error (temp i have made it print to screen what the order number is and the status):

 

pi@raspberrypi ~ $ sudo python OSCommerceClient.py
Serial printer enabled
Starting polling
starting poll worker
poll for orders
starting print worker
starting confirm worker
432 1
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "OSCommerceClient.py", line 122, in pollForUpdates
    orderNum = int(vals[0]);
ValueError: invalid literal for int() with base 10: '\xef\xbb\xbf432'
 
^CTraceback (most recent call last):
  File "OSCommerceClient.py", line 270, in <module>
    time.sleep(60)
KeyboardInterrupt
pi@raspberrypi ~

 

 

anyone that can see where in the code it goes wrong for me? i'm total lost since it has worked for almost an year now....

 

 

EDIT: i have made this printer for 3 pizza deliveries.... one is of course not currently working... the others are....

 

if i call up the file that list pending order on the one that works it is encoded as windows-1252 the other that is not working is UTF-8 (as reported by chrome browser)

 

otherwise if i ask for details in chrome i get this:

 

<html>

     <head></head>

     <body>

      "[432 1,"

      <br>

      "OK]

      "

      </body>

    </html>

 

its the same for both sites... 

 

so cant it be just the encoding alone that can throw it off? and if so how to i change the encoding on those files alone? is the simpelts way to throw them in a sub folder?

Posted

 

Your script does logging... find the file and see if it printed anything

 
import logging//line17


 logging.debug("processing order "+order);  //line 120
 logging.debug("found order "+str(orderNum)+" status "+str(status)+",")//line 125
 logging.debug("skip order "+str(orderNum)); //line 130
 logging.debug("OK at end of list"); //line 133

 

 

Also in above code you have your ip adress listed for the server, is that still the correct IP? (somehow i have a feeling it is where the problem is)

Posted

that part of the code is not used.... only the address listed instead of test.com is used.

 

i plan to clean the code when i have it working again

 

 

EDIT: i see the import logging.... but how do i know what file to search for?

 

i guess this is the downside of having other people do code for you... harder to debug :-/

 

 

Btw... how do i force a charset on a single file in root folder? i tried various tricks via htaccess but chrome still reports utf-8

wanted to test if it made a difference if the php page i call can encoding to something different

 

EDIT2: added this under import logging: logging.basicConfig(filename='example.log',level=logging.DEBUG)

Posted
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): ****

DEBUG:requests.packages.urllib3.connectionpool:"GET /arduino1.php?sc=***** ('HTTP/1.1',)" 200 None

DEBUG:root:processing order 432 1

 

 

So it seems that there is something in front of the order number that i cant see in the browser.... not if i ask to see the source code... nor if i ask chrome to show details

 

 

i have read somewhere that utf-8 adds a BOM ???? could it be that is what throws it off?

 

 

EDIT:  if i just change the server address to the site that encodes to windows-1252 and run the python script again i get:

 



INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): ****

DEBUG:requests.packages.urllib3.connectionpool:"GET /arduino1.php?sc=****('HTTP/1.1',)" 200 None

DEBUG:root:processing order 495 1

DEBUG:root:found order 495 status 1,

DEBUG:root:processing order

 

INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): ****

DEBUG:requests.packages.urllib3.connectionpool:"GET /arduino3.php?sc=****&o=495 ('HTTP/1.1',)" 200 None

INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): ****

DEBUG:requests.packages.urllib3.connectionpool:"GET /arduino5.php?sc=****&s=finished&o=495 ('HTTP/1.1',)" 200$

INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): ****

DEBUG:requests.packages.urllib3.connectionpool:"GET /arduino1.php?sc=**** ('HTTP/1.1',)" 200 None

DEBUG:root:processing order


Posted

i fixed your php-files, these should be working now.

The problem was in arduino3.php

I also took out all line breaks in the end of the files after the ?> Tag.

+ i indent all files so they are better readable.

This should work now.

 

Please report back.

Posted

no the issue was in arduino1.php 

 

the python script on the RPi does not like the "blob" that utf-8 encoding creates....

 

the php files are fine, they generate the output that is needed

 

i tested this by letting the python script work from a site that encodes to windows-1252

 

 

but will have a look

Posted

by blob i mean the ï»¿ that comes in front of the order number, but which is not vissible in a browser...

 

that is when you call arduino1.php.... the "blob" is not there on windows-1252 encoding...

 

i agree thou that the files sure could need better indent etc

 

but the bigger mess is the python script, lots of unused code

Posted

So i have poked arround the net on how to enforce a spec output encoding and i have so far failed...

 

i only want to enforce the output encoding on 5 files and not the whole oscommerce install

 

 

can it even be done?

Posted

thinking of doing the python script more robust to coding issues

Posted

its not the encoding of the python script that is a problem... its the output from the php files when they are called by the python script.... 

 

will be in chat shortly

Posted

the problem with php outputting as UTF-8 is that it send unexpected signs for the python script....

 

in a browser you will not see this as the browser see its UTF-8 and shows it correct....

 

 

its only when you see the raw html data you can tell the difference

Posted

a thanks to  wHiTeHaT  for trying to help.... but as told in chat i dont  give out remote access or passwords.... should not be needed anyway...

 

i just need to figure how to force the webserver at webhosting to output the files in iso-8859-1... i tried to insert 

 

header("Content-Type: text/plain; charset=ISO-8859-1");

 

at the top of the php files but the server still ouputs as utf-8

 

i also tried to force one of the files via htaccess but that did not work either

Posted
$text 'your output';

$newoutput = iconv("UTF-8//IGNORE", "WINDOWS-1252//IGNORE", $text);

The reason i asked these access is that i not want to spend 100 post for such a problem what could be solved in a few minutes.

i am very impatient in such cases.

 

Anyway, that is how i roll.

Posted

did some more testing

 

before i upgraded the shop i keept a backup... i put that backup to a subdomain.... when i look at the store it encodes to windows-1252 like i want

 

but when i call the php files for the printer it goes to utf-8 again....

 

there is one more shop i have yet to upgrade and that works fine.... only difference between that and the shop in subdomain are the database.... the one on subdomain are converted to utf-8.... the shop i have yet to upgrade are in latin1_swedish_ci

 

if i could convert back from utf-8 i would bet that the php files would also show up as windows-1252, but that would screw arround with how oscommerce 2.34 likes the databse....

 

 

so are there other thing i could do?

Posted

well shop runs fine on database with the old encoding... now just need to get the php file to show up as iso too

Posted

So you're getting a UTF-8 Byte Order Mark (BOM) from somewhere? Usually this comes from using a brain-dead editor in UTF-8 mode that "helpfully" inserts a BOM at the beginning of a file that's been edited. It's invisible if you're displaying in UTF-8 mode. While displaying in a single-byte encoding (non-UTF-8), check all your PHP, Python, and data files for BOMs. If any are found, resave the file without a BOM (any good editor should have this setting). If one or more BOMs have gotten into your database, you've have to clean it by manually editing the data. It may not show up in phpMyAdmin if that utility is displaying in UTF-8. Perhaps you'll have to back up (dump) the database to a .sql file, and edit it in non-UTF-8 mode (being careful not to accidentally modify any other data -- I would compare "before" and "after" files to confirm that BOM removal is the only difference). Remember when you import (restore) the .sql file to tell phpMyAdmin that it's UTF-8, otherwise it will think it's Latin-1 and corrupt the data.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...