How to Fix ImportError: No frozen submodule

Python When using Python’s imp module I ran into this error. I’ve seen it a few times and it’s a pretty easy mistake to make, so I just thought I’d pass along the simple fix for Googlers.

Traceback (most recent call last):
  File "module/file.py", line 316, in some_method
    file_, pathname, description = imp.find_module("module", path_to_module)
ImportError: No frozen submodule named /home/user/dev/python/project.module

The Solution

When calling imp.find_module, you should be passing a list of paths to search for the module instead of a single path. In others words…

The Wrong Way

imp.find_module("module", path_to_module)

The Right Way

imp.find_module("module", [path_to_module])

Happy deving!

Regenerating Your SSH Public Key from Your SSH Private Key

Terminal Have you ever found yourself in a situation where you had your SSH private key, but not your public key? Maybe you copied your private key to a new laptop, but then realized you need your public key so your coworker can add you to the new Git repo. Or maybe you just plain lost your public key or have no idea what happened to it. But guess what, that’s not a problem! Because you can regenerate it!

Using ssh-keygen

The ssh-keygen command allows you to regenerate a public key using the -y flag. Using the -t flag you can tell it whether the key is rsa or dsa.

Is my key RSA or DSA?

Chances are it doesn’t matter; ssh-keygen will try to guess based on the input key. However, if you don’t know your key encryption, it’s probably rsa since that’s the default. The filename will also typically tell you, since it’s usually either id_rsa or id_dsa. And even beyond that, if you look at the text in the file, it should be present there as well.

Regenerating a Public Key

Here’s an example:

# ssh-keygen -y
Enter file in which the key is (/home/username/.ssh/id_rsa):
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAr3T65FaSononqBjGEZXMg8x0U3ZjYvZxAUZQA7H27VtPgrn9FhsP8Jn+sp0zOi2nFjDsbXWM5L6OPVg1N0OHpiNcg7I
lrc83GiqVGg2AWeHWWolnOwXIsrfwybVcS6ZSCGbGKVWWL5VB/mt/zzF5WD6bhU+TZXYLq8fZC4sa0sapqVccubKw2YbjA53n0wKxrYLfOjP1k56EfkHzm4n7fmlyFi
3kaCvPo31yaMD3zIVJnl/4wMntnnxqFkG7mEtQ29ngkc5ocgRvSbNNvD9IFNvL/9BqlUtiOUcV790cdoLyd0o1mFV8sGPY3zsL6l3lTkjYDmSXTTnxavjHEudC5w==

BAM! There’s your public key!

Is this safe?

Yes, regenerating your key is completely safe and there’s no reason why you wouldn’t want to do this. Public keys are public, just as their name implies. You can give your public key to anyone.

The private key is the one you should keep to yourself and safe-guard. You should be the only one with your private key, and there’s no reason you should not be able to get a copy of your own public key.

Now save that public key somewhere safe so you don’t have to generate it every time!

Happy authenticating!

PowerShell Object Tutorial

Windows PowershellCreating objects in PowerShell is… strange, to put it lightly–down right awful if you want to be realistic. But even if the syntax is terrible, objects are still nice to use. Here’s a quick primer on how to create and use an object in PowerShell.

Creating a New Object

First let’s create an object using New-Object.

PS > $myObj = New-Object Object

Continue reading

How to Fix “Could not connect to the feed specified” with NuGet and TeamCity

When using NuGet 1.7 with TeamCity 7, I was receiving an error in the NuGet GUI when trying to connect to our NuGet feed. The error in Visual Studio looked like this:

Could not connect to the feed specified at '$the-server/app/nuget/v1/FeedService.svc'. Please verify the package
source (located in the Package Manager Settings) is valid and ensure your network connectivity.

The solution

This is a confirmed bug in NuGet 1.7, as seen in both this NuGet bug report (2066) and this TeamCity bug report (21011). To fix the problem you need to download a newer version of NuGet that contains the bug fix.

NuGet 1.8

As of this blog post NuGet 1.8 isn’t released, but it should be released soon; try updating your plugin to the latest stable version to see if your problem is resolved.

Update: NuGet 1.8 has been released! Upgrade using the Visual Studio Extension Manager or download it here!

Nightly builds

If the latest stable build doesn’t resolve your issue, you can download a nightly build from NuGet’s CI server.
1. Go to NuGet’s CI server
2. Click the link at the bottom to log in as a guest
3. Under the NuGet section you’ll see a couple of options (currently 1.8 and Default)
4. Mouse over the Artifacts link for whichever build you choose (I chose to download a 1.8 build), click VisualStudioAddIn and then NuGet.Tools.vsix
5. Your download should start; let it finish
6. Probably best to close any open Visual Studio instances
7. Run the vsix installer by double-clicking it

Your new NuGet extension should now be installed and your TeamCity feed URL should now work!

Enjoy NuGetting!

How to Fix Errors with the PowerShell WebAdministration Module

Windows PowershellThe PowerShell WebAdministration module can be finicky. If you’re seeing COMException error messages, here are a few things you could try.

WebAdministration Errors

If you import the module using the 32-bit version of PowerShell, you might see the following.

PS > Import-Module WebAdministration
PS > Get-Website
Get-Website : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed
  due to the following error: 80040154.
At line:1 char:12
+ Get-Website < <<<
    + CategoryInfo          : NotSpecified: (:) [Get-Website], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetWebsite
   Command

If you import the module using the 64-bit version of PowerShell, you might see this error.

PS > Import-Module WebAdministration
PS > Get-Website
format-default : Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
    + CategoryInfo          : NotSpecified: (:) [format-default], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.FormatDefaultCommand

Continue reading

Examining and Recursing Objects in PowerShell

Windows PowershellI’m still somewhat new to PowerShell and all the time I find myself wanting to examine objects to see what properties and methods they have available. The documentation on MSDN and around the web is pretty good, but there are still plenty of situations where it’s just easier or better to ask PowerShell to help you out instead. For instance, when you’re using a third-party module that’s sparsely documented you might want to just examine its objects. Or maybe you just don’t feel like going to Google. Either way, here’s a bunch of ways you can get a better look at an object in PowerShell.

Continue reading

How to Install the Service Trace Viewer Tool (SvcTraceViewer.exe) to View *.svclog Files

Microsoft .NETI work with WCF services day to day, so sometimes I need to check the service logs to debug an issue or provide a stack trace for a bug report. To view *.svclog files, you need to install the Service Trace Viewer Tool from Microsoft.

Installing the Service Trace Viewer Tool

1) Go to the Windows SDK page and click Install Now
2) On the next page click Download and then run the web installer (winsdk_web.exe)
3) The default installation will install a lot of development tools, including the Service Trace Viewer Tool. But if you’re a minimalist and you’re just looking for the Service Trace Viewer Tool, just install the .NET Development Tools.

Install Service Trace Viewer

My machine required those additional reference assemblies, but your mileage may vary depending on what you’ve already installed.

Good luck debugging!

How to Fix “IsCleanMSDeployPackageNeeded” task failed unexpectedly

Microsoft .NETWhen deploying .NET projects, it’s handy to package them up using MSBuild. Recently I ran into an issue where my deployment scripts were working locally, but not on the build server (TeamCity). The error I was receiving looked like this:

C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018: The
        "IsCleanMSDeployPackageNeeded" task failed unexpectedly.

The solution

It was clear to me that something was awry on the build server, but I wasn’t sure what that might be. After looking into it, I realized that packaging your .NET projects like this utilizes Microsoft’s Web Deploy library, which must be installed on the machine.

Click here to visit Microsoft’s official Web Deploy page and download the package.

This must have already been installed on my development machine because I have IIS running; since the build server doesn’t have IIS installed, it needed the package to be installed separately.

Happy coding!

Enabling SSH/SFTP Updates in WordPress on Amazon EC2 and CentOS

WordpressThe WordPress blogging platform does support installing and updating your plugins using SSH/SFTP! So, why is it that it doesn’t show up as an option when updating your plugins?

Well, as it turns out, your PHP installation must be configured to support SSH before this option will show up in your WordPress dashboard. In this article I’ll explain how to set this up using just a few simple commands or a plugin.

Continue reading

Installing build-essentials in CentOS (make, gcc, gdb)

CentOS IconOnce upon a time I was a very avid desktop user of Ubuntu Linux. As a software developer, I would usually need the standard build tools installed on my machine.

Installing build tools in Debian/Ubuntu

In Debian/Ubuntu, you can install the typical build tools by installing the package build-essentials, which is just a pseudo-package that downloads all the popular development packages:

# apt-get install build-essentials

Installing build tools in CentOS

Since I prefer CentOS as my server platform, I also occasionally need to install packages using yum.

To install the common build tools using yum in CentOS you’ll want to install the group package “Development Tools”, which is similar to build-essentials in Debian/Ubuntu flavors of linux. You’ll probably also want to install kernel-devel and kernel-headers if they’re not already installed:

# yum groupinstall "Development Tools"
# yum install kernel-devel kernel-headers

This should give you a copy of make, gcc, gdb, and all those other tools you were looking for.

Happy hacking!