Python Crypto not found in bundle

Hi @Olu

I tried the steps provided in the link u provided. But I’m kinda lost in terms of the instruction. Appreciate if you could kindly guide me through.

It’s as simple as creating a requirements.txtfile and runningpip3 install -r requirements.txt --prefix vendor`

I’m running tyk in a docker env. Where do I place this requirement.txt? In the plugin bundle folder?

You may need to manually add the vendor directory to the bundle.zip with something like this:
zip -ur ${bundle}.zip vendor/

When I setup python venv in the bundle folder and install the library. It is residing in venv/lib/python3.7/site-packages/Crypto so how does this translate to the command above. I tried to put zip -ur bundle.zip venv/ and it does not work.

Also be aware that you need to be careful about loading these import within your python scripts.
I use this sort of thing

bundle_dir = os.path.abspath(os.path.dirname(__file__))
for lib_dir in [ 'vendor/lib/python3.7/site-packages/' ]:
  vendor_dir = os.path.join(bundle_dir, lib_dir)
  sys.path.append(vendor_dir)

import jwt

I tried the above code and change to:


import os
import sys
bundle_dir = os.path.abspath(os.path.dirname(__file__))
tyk.log("bundle_dir = ({0})".format(bundle_dir),"debug")
for lib_dir in [ 'venv/lib/python3.7/site-packages/']:
    vendor_dir = os.path.join(bundle_dir, lib_dir)
    tyk.log("bundle_dir = ({0},({1}))".format(lib_dir, vendor_dir),"debug")
    sys.path.append(vendor_dir)

import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes

Would appreciate if any help/advise given. Thanks.