Saturday, May 05, 2018

Setup WiFi to auto-connect regardless of logged in state (UPDATED)

There are plenty of times where I would like to start up my desktop machine (running Ubuntu 16.04 LTS) and just have it boot and me log into it via SSH so that I can get some work done.  Well, in order to achieve that wish, you need to have your wifi connection auto-connnect at boot time.

To do this, there are some things you need to do:

1.  Go to your wifi connection in the upper right of your screen and click on "Edit Connections".
2.  Once in there, you need to click on your connected wifi ssid and select "Edit".
3.  Go to the "General" tab and select "All users may connect to this network".  (without this, the rest of this is moot and it will not work)

Ok, that is the only gui portion of this setup.  Next:

4.  Create the file /etc/wpa_supplicant.conf and add the content that follows:

ctrl_interface=DIR=/var/run/wpa_supplicant group=wheel
network={
  ssid="your_connection_ssid"
  scan_ssid=1
  key_mgmt=WPA-PSK
  psk="password"
}
In the above code, you will input your ssid that you would like to connect to and also enter your password for the connection.  If you are using an encryption method other than WPA/WPA2, then you will need to reference the man page for wpa_supplicant.conf.  There are plenty of examples to help you out. 

After you have that file all setup, save it.

5.  Issue the following command on the command line, as root or with sudo:

wpa_supplicant -B -i wlp4s0 -c /etc/wpa_supplicant.conf

You should see a message that says something to the effect that wpa_supplicant initialization was successful.

After you have completed those steps, go ahead and reboot the machine and watch the login screen.  If all is correct and right with the configuration, you should see the wifi connection show as connected.  You can test this by ssh'ing to the machine.  Enjoy!


UPDATE:  I took the opportunity to reinstall my Linux system to go from Ubuntu 16.04 LTS to Ubuntu 18.04.  I know its a bit extreme to do a full re-install, but:

1.  An distribution upgrade wasn't yet available
2.  There wasn't anything I couldn't re-setup on the machine
3.  Ubuntu moved away from Unity to the Gnome desktop, so I wanted everything clean and fresh.

I will say this though, auto-connection of the wifi (seeing as how you tell it how to connect during installation) just WORKS with Ubuntu 18.04.  You just have to make sure to install the openssh-server package.

Tuesday, May 01, 2018

How to list available versions of a Pypi package

While working on requirements that someone had for a pypi package, I found myself needing to list out the versions of the package that were available.  I didn't want to have to go to the pypi website, navigate to the package and then figure out how to see the available versions.  So, to the Googles I went.

In order to install a specific version of a package, you would run:

pip install =1.0.0

in order to install version 1.0.0 of said package.  But, if you provide nonsense as the option, like so:

pip install =blah

then what you get back is an error listing all of the available versions for that package:


> pip install mod_wsgi==blah
Collecting mod_wsgi==blah
Could not find a version that satisfies the requirement mod_wsgi==blah (from versions: 4.1.0, 4.1.1, 4.1.2, 4.1.3, 4.2.0, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.2.5, 4.2.6, 4.2.7, 4.2.8, 4.3.0, 4.3.1, 4.3.2, 4.4.0, 4.4.1, 4.4.2, 4.4.3, 4.4.4, 4.4.5, 4.4.6, 4.4.7, 4.4.8, 4.4.9, 4.4.10, 4.4.11, 4.4.12, 4.4.13, 4.4.14, 4.4.15, 4.4.16, 4.4.17, 4.4.18, 4.4.19, 4.4.20, 4.4.21, 4.4.22, 4.4.23, 4.5.0, 4.5.1, 4.5.2, 4.5.3, 4.5.4, 4.5.5, 4.5.6, 4.5.7, 4.5.8, 4.5.9, 4.5.10, 4.5.11, 4.5.12, 4.5.13, 4.5.14, 4.5.15, 4.5.16, 4.5.17, 4.5.18, 4.5.19, 4.5.20, 4.5.21, 4.5.22, 4.5.23, 4.5.24, 4.6.0, 4.6.1, 4.6.2, 4.6.3, 4.6.4)
No matching distribution found for mod_wsgi==blah

Good to know its that easy.

Sunday, April 29, 2018

python pip throwing SSL: TLSV1 alert (SOLUTION)

I recently ran into an issue with Python pip, where I attempted to run a 'pip install' of a module and was presented with the following error:
> pip install pymongo
Collecting pymongo
Could not fetch URL https://pypi.python.org/simple/pymongo/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Could not find a version that satisfies the requirement pymongo (from versions: )
No matching distribution found for pymongo

No matter what I did (install, update and even just search the pip repository) I was presented with this same error.  It was certainly a hard, fast stop to whatever I was attempting to do.

But, after some googling and reading of many people's accounts of their trials and tribulations attempting to solve it, I finally found a solution that works.  I happened upon the this posting on StackOverflow, which leads you to the fact that you have to upgrade pip.  Unfortunately, attempting to upgrade it with itself will fail as above.  But, you should instead run the following:

curl https://bootstrap.pypa.io/get-pip.py | python

That upgraded pip directly from the website using its install script.  It is a work around, yes, but one that seems to have worked for me (and apparently others).  Hopefully this solves your issue(s) as well.

**UPDATE: You will need to run the curl command in each virtualenv environment that you have, as each one will have its own installation of python.

Saturday, December 16, 2017

'_remove_dead_weakref' error after upgrading to Ubuntu 17.10

Well, after finally getting my Flask app running and returning data, I upgraded my system to Ubuntu 17.10 (from 17.04).  Today, I tried to start my flask app and was greeted with a bunch of Python error output and the following error:

ImportError: cannot import name '_remove_dead_weakref'

I was baffled as the app worked the day before.  So after some digging around the Googles, I found that the issue was caused by my upgrade to 17.10.

The fix....... delete your virtual environment and rebuild it.  I am not saying delete your project directory, I am saying delete your envs directory (which is where the executables for the virtual environment are.  Some people put it in the same directory.  If you are like me, you have a central location where you keep them. 

You will need to remove that entire directory, rebuild it and then re-run the virtualenv command to create the virtualized environment and then install any modules that you had previously installed (as they get stored in the directory structure you just deleted.  After that, your app and its parts should work fine.

Wednesday, December 13, 2017

Starting Out (and pulling my hair out) with Flask

Recently I started learning the Flask web framework.  Mostly because I have been doing a bunch of Python coding and would like that to bleed over a bit into the web development arena.  The need is not really out of anything work-related, its more of a personal project need.

I can say, though, that getting apache and Flask operating together has certainly added a few grey hairs to my head, mostly in frustration.  There are plenty of resources ( if you search the Googles) for setting up Apache web server and Flask, to work together.  But I have to say that, as great as the resources that are out there, are, there are a few (pertinent) details that were left out of most of them that I will now cover.

First, working in a Virtual Environment does not have all of the same settings as not working in one.  If you look at this link, you will see (near the bottom of the document) that there are a couple of things you have to set in your .wsgi file, to specify the load paths for your virtual environment. 
NOTE: It is important to note that that link is the same root site for the Flask link above.  So they definitely have a lot of documentation on their product.

Now, while the above is important, it didn't solve my issue, which is that on a machine remote to where I am running my Flask app and web server, I was not able to go to http://:5000 (the port Flask runs on) and see the page displayed as expected.  Instead I received a typical error page stating that the page could not be loaded.  This got even more frustrating with each new thing that I tried or modified to get it working.  No matter how seemingly possible of a fix, it didn't work.  Until.....

I found a StackOverflow thread about running a Flask app under the Apache web server.  I read the person's question and went through their code (seeing all the similarities) and there it was... a setting that no other site had mentioned.  Not even the video tutorial I was going through.  It was part of my Flask app's __init__.py file and the part in question looks like this:
app.debug = True
app.run(host='0.0.0.0')
The first line is inconsequential and just turns on debug mode.  The second line was 1/2 different from mine, but crucially different.  I had the app.run() that all the tutorial's had mentioned, but I did not have the host='0.0.0.0' portion.  I put it in, started up Flask (by running the __init__.py file) and VOILA!!!  I had the output that I expected to see in my browser. 

Needless to say, it was certainly a learning experience ( as I now have plenty of notes for running a Flask app with Apache).  Now I can get on with my learning of the Framework since the tedious job of getting the web page serving is now out of the way.  Yay!



Wednesday, March 01, 2017

I give you.... PyBlueprint

About 3 years ago (or so), I created a bash script for starting a new Python project.  I was tired of setting up each new project by hand and wanted a quicker way to do it as a time saver.   That endeavor yielded a script that I have used for the last 3 years.

While the script works fine from a bash perspective, I was not yet happy with it in that state.  So, I embarked on re-writing it in Python.  I didn't get the chance to work full force on it right away, but over the last week or so, I have made an immense amount of progress on it.  So much, that I am ready to announce the project for people to download, play with and hopefully enjoy.

Overview:

PyBlueprint's whole purpose is to create a base project directory for new Python projects.  Some of the features that the script has are:

    - Creates project directory for you and populates it with a base set of files (script, README, etc)
    - Initializes a new git repo (or not, if that is your choice)
    - Create a new Github or Bitbucket repository for you to push your code to

I could be over estimating, but I would say that this project saves me about 5-10 minutes of initial project setup so that I can get to coding my projects quicker.

I know that not everyone works in the same manner and we each have our own requirements.  I just ask that if you are a python developer, please give this a shot and see if it works for you.  If there are suggestions, I am open to them, please just open an issue in the project.

Project Link:  https://bitbucket.org/numberwhun/pyblueprint

UPDATE: I realized a short time ago that I still had the repository set to be private.  I have changed it to be a public repo.  Sorry about that!

Wednesday, September 14, 2016

An Update On Combining PDF Files

Back on January 19th, 2009, I wrote a blog post about combining pdf files into one.  This is something I do now and again with one of my hobbies.
When I wrote the aforementioned article, I was only doing this on a Linux server.  Since then I have become an avid Mac user, as well as continuing my love and infatuation with Linux.  On Mac, you have a plenty of the Linux utilities you are used to, but some take some searching, and even then they may not exist or be ported.
In my quest to find an easy way on Mac OSx to combine PDF files, I did run across one.  It is called, believe it or not, "Combine PDFs".  I know, simple name, but believe me when I say that this GUI tool is pretty awesome!  You simply select the files you want to combine and it then not only shows you the order it is putting the in, but it also allows you to preview each page.
The tool is installed using brew on Mac.  If you don't have brew, you'll have to either install it.  If you don't use brew, you can always try to find it for download.  But, I recommend using brew as its pretty handy for obtaining and installing software packages you need and that aren't available through the app store.
If you do use brew, you can install it with the following command:
  brew install Caskroom/cask/combine-pdfs
After that finishes, you will see it in your applications list, as it is a GUI based application.

Enjoy!

Friday, September 09, 2016

Python pip Broken After Upgrade To OSx El Capitan

Wow its been a long time since I blogged.  I have no excuse other than things have been a touch crazy.  My work recently started allowing us to upgrade our Mac's from Yosemite to El Capitan.  For me the upgrade only took about 45 minutes, which is pretty quick in the grand scheme of things.  The download is a little over 6 gb and went pretty quickly.  

I was going along fine until today when I tried to install a new module using pip.  About 1/2 way through the installation I was presented with the following output:

    In file included from src/lxml/lxml.etree.c:321:
    src/lxml/includes/etree_defs.h:14:10: fatal error: 'libxml/xmlversion.h' file not found
    #include "libxml/xmlversion.h"
             ^
    1 error generated.
    Compile failed: command 'cc' failed with exit status 1
    creating tmp
    cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitf3OxN6.c -o tmp/xmlXPathInitf3OxN6.o
    /tmp/xmlXPathInitf3OxN6.c:1:10: fatal error: 'libxml/xpath.h' file not found
    #include "libxml/xpath.h"
             ^
    1 error generated.
    *********************************************************************************
    Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
    Perhaps try: xcode-select --install
    *********************************************************************************
    error: command 'cc' failed with exit status 1
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-9IduXA/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-RgavmY-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-9IduXA/lxml/

I had installed other modules last week, but then I realized that that was prior to my upgrading.  I looked at the above output and noticed the line:

     Perhaps try: xcode-select --install

OF COURSE!!!  Although I upgraded, and XCode had been upgraded to, I still needed to do some things with XCode to get things going again.  First, I opened XCode and went through its initial startup after an upgrade.  A bunch of clicking and things were good there.  I then opened up my command line and, prefixing the command with 'sudo', I ran the 'xcode-select --install' command from above.  This presented me a pop-up window to install tools.  So, I accepted and allowed it to install.  Once finished, I tried my pip module installation again and VOILA!!!!  It worked!!!

So, in this lesson, always make sure to update your XCode and xcode-select before moving on after an upgrade.

Wednesday, February 10, 2016

Where Is All My iPhone Space???

So recently my work upgraded my iPhone to an iPhone 6.  In preparation for this, I plugged in my old phone and offloaded all of my photos.  I made sure to delete them so the phone was cleaned off (as I always did.   To my amazement though, when going into iTunes, I noticed that there was still about 2Gb of space used up by photos.

I navigated over to Photos on my phone and there was nothing.  I had emptied out all my stuff.  I did a search and something said to turn off photo synching in iTunes.  I remember I had done that a while ago, but checked it and sure enough, it was off.

So, a bit more digging and I discovered that apparently, there is an 'issue' (I call it that, but Apple may call it a feature), where there are deleted files that are hidden and not visible, remaining on your phone.  You cannot see them or find them..... so you think.    Time to have some fun.

If you would like to clean these hidden pictures off of your phone, do the following:

- go to Settings-> General -> Date & Time
- Uncheck "Set Automatically" and then set the date to August 1st, 2014 (I don't know why, its a magical date apparently.

After you have done that, get out of settings and open Photos.  You should now see a bunch of items in the deleted folder. Voila!! Your hidden photos that you have probably already offloaded to your laptop.

I don't know why Apple hides them, but I really wish one of their developers would look at this issue and make the phone do the right thing.  Our phones need space, not things we deleted taking up said space.

All you need to do with the deleted items is go into the folder, touch "Select" and select all items and then click 'Delete' and they will be gone...... Space recovered.  After that, go back to the Date & Time above and turn back on Set Automatically and your date should fix itself.

Enjoy the added space to your phone!

Thursday, January 07, 2016

Keep Your SSH Session ALIVE!!

Most of us have had those days where we have a bunch of windows open, ssh'd into multiple servers.  You get caught up working on one of those servers and forget about your other ssh sessions.  Or, if you are like me, you are using something like screen/tmux and have many sessions going at the same time that you want to keep alive.

Well, with the default ssh setup, there is a setting in your ssh_config file called "ServerAliveInterval".  Initially (at least on my system) it is commented out and also has a value of zero (0).  

In order to keep your sessions alive indefinitely, you will need to uncomment that variable in the ssh_config file and set it to a value other than zero.  I have mine set to 60. 

What this variable does is tell ssh that it needs to send a packet across the wire to the connected server so that there is traffic, keeping the connection active, not letting it time out. 


So, by to keep your sessions alive, you will need to make the changes as above, but also, do not forget that this change will only effect new connections made after you save the change.  If you have active connections, you will need to exit them out and restart them.  If you don't, they will still be subject to the same issue you just corrected.

Go now, keep those connections alive! 
 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.