python3 datafeed implementation

I'm trying to wrap my head around decoding the RC4 encrypted feed of Foxycart. I have the php example running and have verified that the url unquoting is working correctly. As soon as i enable the encryption it starts failing though.

My posted data looks like this (url encoded):

after url decoding and decrypting i get this python byte string:

I've looked at existing python implementations on the integrations page, but they yield the exact same result.

Did anything change in the way this should be implemented?
  • fc_marijafc_marija FoxyCart Team
    Hi @markofabrique

    We'll spend some time on this and see what we can figure out. Let us know if you make any progress in the meantime.
  • fc_marijafc_marija FoxyCart Team
    Hi @markofabrique - Can you post your code somewhere we can check it out, such as The forum doesn't do whitespace in code blocks.
  • Here's my debugging version

  • fc_marijafc_marija FoxyCart Team

    Have you tried the ARC4 class from our Django example? I pulled it out and put it here:

    The entire example is here:
  • this is interesting, it seems they yield different results but no working example as of yet:

    Foxycart python ARC4:
    、f<}e;ret *tオi)g, BoMhPahE

    python Crypto ARC4:


    Does this mean the ARC4 implementation is inconsistent cross platform?
  • fc_marijafc_marija FoxyCart Team

    Still with you here! I'm using this class called FoxyData, which creates a FoxyData object containing all the Transactions in the datafeed. Perhaps I'm missing something, but I'm not seeing anything in the code you provided that does something similar. The ARC4 class that I shared with you earlier and this are in the same python file in the Python/Django example on our wiki. So, basically, we are 1. Decoding, 2. Decrypting, 3. Creating an object with for accessing the transactions

    I believe all the examples in our wiki are 2.7, so you may need to do some translation to 3. Also, I am using urllib.unquote_plus() on the returned data, but I know that 2.7 and 3 are different in that regard. I thought I would just throw that out there in case it's relevant. Here's a link to the file:

    I have the decrypting and parsing working in 2.7, so if you're interested in digging around at that let me know.

    Hope my post has some valuable info for you. Let us know how it turns out or if we can provide additional pointers.
  • Thanks for this. I've got a python2 version now working. It seems the unquote_plus function yields completely different results with Python3. The output looks a lot different. I will look into this and if i get it working will post back!
  • I've been doing some bughunting and got it working.

    It seems the Python3 ARC4 function yields a different result (it looks like a byte object). So I've used the Python2 example which does work. Next to that it is crucial that unquote_plus gets and encoding parameter. Since Python3 does utf-8 by default, and so does unquote_plus.

    So by changing this simple line it works flawlessly:
    unquote_plus(post, encoding="latin-1")

    Might be a good idea to state in the docs that the Foxycart POST data is latin-1 encoded :)
  • fc_marijafc_marija FoxyCart Team

    Glad you got it working, and thanks for your feedback. So did you use the python2 example and then get it working for python3 or did you tweak your python3 code from earlier?

    Since you now have a working python3 example, any chance you'd be willing share it on our wiki for other users?
  • Sure, however I'm not sure how I can post something on your wiki. Let me know then I can post some code.
  • fc_adamfc_adam FoxyCart Team
    edited May 2017

    Thanks! If you'd like - you can simply put it in a pastebin and we can get it added to the wiki for you.
  • Here you go! I just customised a few minor things like an extra variable etc.
  • fc_marijafc_marija FoxyCart Team
    Thanks @markofabrique, that really helps our users.
Sign In or Register to comment.