Making MITM proxy run on Mac - macos

I need to make use of python's mitmproxy. I have installed it successfully. However when I run mitmproxy command on my terminal it gives me a stack trace like the below :
File "/usr/local/bin/mitmproxy", line 9, in load_entry_point('mitmproxy==0.13', 'console_scripts','mitmproxy'()
File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 558, in load_entry_pointreturn get_distribution(dist).load_entry_point(group, name)
File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 2682, in load_entry_point return ep.load()
File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 2355, in load return self.resolve()
File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 2361, in resolve module = import(self.module_name, fromlist=['name'], level=0)
File "/Library/Python/2.7/site-packages/libmproxy/main.py", line 7, in from . import version, cmdline
File "/Library/Python/2.7/site-packages/libmproxy/cmdline.py", line 5, in from netlib import http
File "/Library/Python/2.7/site-packages/netlib/http.py", line 7, in from . import odict, utils, tcp, http_status
File "/Library/Python/2.7/site-packages/netlib/tcp.py", line 26, in 'TLSv1.2': SSL.TLSv1_2_METHOD, AttributeError: 'module' object has no attribute 'TLSv1_2_METHOD'
I tried debugging the issue through some Googling and looks like I needed to upgrade my pyOpenSSL.
To know the current version of my PyOpen SSL I did the following on the Python prompt and got the ouptut as shown below to be 0.13:
>>> import OpenSSL
>>> print OpenSSL.__version__
0.13
So I tried upgrading the my pyOpenSSL using the below :
sudo pip install --upgrade pyOpenSSL
ans successfully did so, as when I ran the above again I received the following in the first line of the output :
Requirement already up-to-date: pyOpenSSL in /Library/Python/2.7/site-packages
Just to cross verify I went to the above path and found the PyOpenSSL dir as PyOpenSSL-0.15.1.dist-info. So am guessing PyOpenSSL was actually upgraded to the latest version.
However, when I ran the below on Python prompt again I received the version again as 0.13. Ideally I was expecting it to give the updated version now.
>>> import OpenSSL
>>> print OpenSSL.__version__
0.13
Some blogs suggested that if I have a virtualevn installed, it might interfere with the above. So I uninstalled virtualenv as well using
sudo pip uninstall virtualenv
I am still not able to get mitmproxy running. And when I run mitmproxy, I still get the same error as above.
Please let me know what am I missing and how to get mitmproxy running.

So it happens yet again. :P I could figure out the problem with the above approach and the solution to it as well on my own - OF COURSE - with the help of some friends and blogs !
So appears that the problem was actually because of MANY out-dated dependencies : -
Outdated OpenSSL -
current version displayed using OpenSSL version -a
Awesome help found # http://javigon.com/2014/04/09/update-openssl-in-osx/ to update OpenSSL and from a friend (https://anantshri.info/) who pointed out the issue itself initially.
Outdated pyOpenSSL - upgraded using the below which of course upgraded the same.
sudo pip install --upgrade pyOpenSSL
Then why was the below still showing an outdated version ?
import OpenSSL
print OpenSSL.version
0.13
because there were 2 different OpenSSLs in the system. One that was installed by pip and the other that was by default present in OSX. Again awesome help found # https://github.com/pyca/pyopenssl/issues/128
some useful commands that helper were :
pip show pyOpenSSL - gives as output :
Name: pyOpenSSL
Version: 0.15.1
Location: /Library/Python/2.7/site-packages
as part of the output - indicating that the OpenSSL installed using pip is actually 0.15.1
cross verify using :
ls /Library/Python/2.7/site-packages/ | grep OpenSSL - gives as output:
pyOpenSSL-0.15.1.dist-info
Now the path below also had another copy of OpenSSL :
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL and cat version.py in the above dir gave the below as part of output :
version = '0.13.1'
indicating that the cause of the issue with the import statement showing the outdated python version.
And the above itself was the root cause for mitmproxy also not working
because mitmproxy was unable to use the latest version on OpenSSL.
So solved the problem by just replacing the OpenSSL in the above path (which was outdated) with the updated one from /Library/Python/2.7/site-packages/
where
cat ./OpenSSL/version.py gave as output (once again just to cross-verify)
version = '0.15.1'
And now the import statement reported the right version of OpenSSL.
Uninstalled mitmproxy using sudo pip uninstall mitmproxy - successfully uninstalled. Also uninstalled virtualenv. (not sure of the above 2 was required !)
Reinstalled mitmproxy as sudo pip install mitmproxy - Successfully done !
And ran mitmproxy now from the terminal wihtout a glitch ! :)

Related

Pip suddenly cant find or install any package

Suddenly pip cant install or find any package, it cant even figure out its own version.
I reinstalled python multiple times, i have the latest version of python 3 and pip. I also tried to clear pip cache. Nothing works, this is really annoying...
Errors:
>pip install redblacktree
ERROR: Could not find a version that satisfies the requirement redblacktree (from versions: none)
ERROR: No matching distribution found for redblacktree
WARNING: There was an error checking the latest version of pip
>pip config list
freeze.user='yes'
global.index-url='http://pypi.org/simple'
global.trusted-host='pypi.org'
install.user='yes'
list.user='yes'
uninstall.user='yes'
I fixed it by locating the pip.ini config file and removing the line index-url = http://pypi.org/simple

PyMesh problems with Setup on Windows10 and Error using Docker Version

I want to install PyMesh on a Windows 10 PC, if possible it should be installed in the side-packages of an interpreter delivered with the IDE we use.
I tried the way to run the setup discribed here
https://pymesh.readthedocs.io/en/latest/installation.html
so the part :
git clone https://github.com/PyMesh/PyMesh.git
cd PyMesh
git submodule update --init
worked without any problems.
I am not sure on windows if I now just can write
set PYMESH_PATH = path
and if i can use the path "...\PyMesh\PyMesh" here?
so i left out this part
I installed numpy and scipy (allready installed)
and nose because it is mentioned in the requirements.txt.
So my numpy scipy and nose versions are
numpy 1.19.1
scipy 1.6.0
nose 1.3.7 (same as requirenments)
and just run the setup.py with admin rights
python .\setup.py install
which also seemed to work but i got an error trying
python -c "import pymesh; pymesh.test()"
from the PyMesh folder
saying ModuleNotFoundError: No module named 'PyMesh'
or if i go up one Folder doing the same
saying AttributeError: module 'PyMesh' has no attribute 'triangle'
I found this link ImportError: No module named PyMesh
but i just dont know what i should type in there
I tried to install via pip by using pip install pymesh
but pip Installer gives me a different library.
So i tried in the docker version and in docker i tried the pymesh.load_mesh method with an stl File
but got
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
I dont know if this is just the stl format (expecting binary getting ascii or vice versa)
The stl file itself can be opened so shouldnt be corrupted.
So is there a different way to install pymesh? A wheel would be great. Is it possible to install pymesh to the side-packages of a given Interpreter? Did someone else allready had the same error in Docker and knows the issue
thank you for your help

ImportError: No module named googlemaps

I've installed this package via pip27 on macports. My OS is OSX El Capitan 10.11.6. My python install is 2.7.10.
I'm trying to run an example script that imports googlemaps module, but I keep getting that ImportError. I have a feeling that it's how pip installed it and the reason why python can't find it, but I'm relatively new to pip so I don't know where to start investigating.
I also tried googling for a fix but no dice. Any idea what's happening here?
Here's my code:
import googlemaps # can't import
import argparse
from datetime import datetime
# collect args for lat, long, # of addresses, radius of search
parser = argparse.ArgumentParser(description='Randomize addresses on Google Maps')
parser.add_argument('-lt', '--latitude')
parser.add_argument('-lng', '--longitude')
parser.add_argument('-n', '--count')
parser.add_argument('-r', '--radius')
args = parser.parse_args()
print('Results: ', vars(args))
Error message:
Traceback (most recent call last):
File "randomize_addresses.py", line 1, in <module>
import googlemaps
ImportError: No module named googlemaps
Found a fix. I uninstalled googlemaps via pip and then reinstalled using easy_install. Apparently OSX doesn't like pip.
Looks like you used pre-installed python since you mentioned version 2.7.10 (default version shipped with macOS) which is located at /usr/bin/.
MacPorts installs binaries and libraries under /opt/local. Try to install python via MacPorts and run the program again. Python and pip should both be linked so that packages installed via pip is available to python.
In this case packages installed using pip27 would be available to python27 installed via MacPorts and not /usr/bin/python.
Another way would be to download get-pip.py and install it against /usr/bin/python (pip installation guide).
Note: Make sure you are using python installed via MacPorts. To check this run which python, it should show something like /opt/local/bin/python2.7

kmpfit module not in Kapteyn v2.2 module list

I am using Python 2.7 through Anaconda 2.7.8 and need Kapteyn 2.2 to perform Non-linear Least Squares fitting easily (it is probably an alternative to Scipy.optimize.leastsq() for dummies like me!).
After copy-pasting this from a previous post here on Stack Overflow:
conda install -c https://conda.binstar.org/dhirschfeld pyodbc
and then running on my cmd (as I did not have pyodbc installed I think, because of which maybe the command prompt on my Windows 7 64-bit system was not responding well to python setup.py install inside the Anaconda directory where I unzipped the Kapteyn .zip file downloaded from University of Groningen website.
But, after the installing pyodbc properly and running python setup.py install, the cmd gave me an error saying error: command 'C:\Users\windows 7\Anaconda\Scripts\gcc.bat' failed with exit status 1. Later, when I tried to import kmpfit module (needed for Non-linear least square fitting with Kapteyn), here is the problem:
import kapteyn
help(kapteyn)
Help on package kapteyn:
NAME
kapteyn - Kapteyn package.
FILE
c:\users\windows 7\anaconda\kapteyn\__init__.py
PACKAGE CONTENTS
_ni_support
celestial
doccer
filters
interpolation
maputils
mplutil
positions
rulers
shapes
tabarray
wcsgrat
DATA
__all__ = ['celestial', 'wcs', 'wcsgrat', 'tabarray', 'maputils', 'mpl...
__version__ = '2.2'
VERSION
2.2
As you can see, there is no module named kmpfit (or even wcs) here. But according to http://www.astro.rug.nl/software/kapteyn/intro.html, these two should be there.
Kindly help. I have never imported any module before.
Thanks in advance...:-)
I just managed to get this working (on Mac OSX, so you may have to adjust this). My steps were:
$ conda install pyodbc (didn't need to go through binstar)
Download & unarchive the kapteyn package, then navigate to its directory
$ python setup.py install, which used my OS's C compiler and Anaconda's python, and installed kapteyn to my anaconda distro's site-packages, as it should.
Check that kmpfit.so is in the kapteyn folder in site-packages, showing that kmpfit installed correctly.
>> from kapteyn import kmpfit failed, ImportError: cannot import name kmpfit. I did some digging and discovered that it was still importing kapteyn from the folder that I downloaded, not from site-packages.
Delete the downloaded kapteyn folder, then try again. It worked!

How to install Scrapy on Mac OS X 10.7 ? (lxml error)

I'm a total newbie concerning Python and I have trouble installing Scrapy on Mac OS X 10.7. I've tried a lot of different things, but in summary, when I run:
scrapy startproject tutorial
I've got these errors :
ImportError: dlopen(/Library/Python/2.7/site-packages/lxml/etree.so, 2): Symbol not found: ___xmlStructuredErrorContext
Referenced from: /Library/Python/2.7/site-packages/lxml/etree.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/lxml/etree.so
After a lot of googling, I've followed this post and tried:
python setup.py build --static-deps --libxml2-version=2.7.8 && pip install lxml
but it tells me:
RuntimeError: ERROR: Trying to build without Cython, but pre-generated 'src/lxml/lxml.etree.c' is not available (pass --without-cython to ignore this error).
And if I run the same command with the —without-cython option, I get:
error: command 'llvm-gcc-4.2' failed with exit status 1
(though I've installed XCode command line tools)
Thanks in advance for your help !
(fyi, I am using MacPorts and pip install…)
You mention Macports at the end and also pip. I think you are mixing up packaging and installation methods.
The first import error should not be seen using a macports python as it puts its libraries under /opt/
As you have started on macports I would use the easy way
port install py27-scrapy
This will install all the needed packages (including python and lxml) to get scrapyto work.
To run scrapy you would need to use the macports python in /opt/local/bin/python2.7. This can be set as the default python if /opt/local/bin is on your path and you run port select to choose this as the python found. The scrapy executable script is /opt/local/bin/scrapy-2.7 Version numbers are used because you can have multiple versions of python working at once.

Resources