Where does this derivation of the Fourier Series for csc(x) go wrong? In this post, the following derivation for the Fourier series of csc(x) is given:

\begin{align}
\csc x
&= \dfrac{1}{\sin x}\\
&= \dfrac{2i}{e^{ix}-e^{-ix}}\\
&= \dfrac{2ie^{-ix}}{1-e^{-2ix}}\\
&= 2ie^{-ix}\sum_{n\geq0}e^{-2inx}\\
&= 2i\sum_{n\geq0}e^{-(2n+1)ix}\\
&= 2\sum_{n\geq0}(i\cos(2n+1)x+\sin(2n+1)x)
\end{align}
  now take the real part of both sides.

This seems to give the right answer, but has the very confusing property that somehow we end up, midway through the derivation, with a complex function on the right side, which we need to correct at the end by taking the real part. Since each step is supposed to be equal to the last, where does the complex part come from?
One obvious problem is in using the Taylor series at step 4, since $e^{-2ix}$ is right on the boundary of the radius of convergence of $\frac{1}{1-x}$. But how does this then yield the right answer so long as you just take the real part?

The imaginary part actually seems to vanish — except at $x=0$ where it's infinite.
The Fourier cosine series of $\delta(x-\epsilon)$ is given by
$\frac{1}{\pi} + \sum_{n=1}^{\infty} \frac{2}{\pi} \cos n\epsilon \cos nx.$
Letting $\epsilon \to 0$ gives
$\delta(x) = \frac{1}{\pi} + \sum_{n=1}^{\infty} \frac{2}{\pi} \cos nx.$
Thus, 
$$
\cos x + \cos 2x + \cos 3x + \cdots
= \sum_{n=1}^{\infty} \cos nx 
= \frac{\pi}{2} \delta(x) - \frac12.
$$
We get the terms for even $n$ by replacing $x$ with $2x$:
$$
\cos 2x + \cos 4x + \cos 6x + \cdots
= \sum_{n=1}^{\infty} \cos 2nx 
= \frac{\pi}{2} \delta(2x) - \frac12 
= \frac{\pi}{4} \delta(x) - \frac12,
$$
where in the last step $\delta(ax) = \frac{1}{|a|} \delta(x)$ has been used.
The sum of terms with odd $n$ is therefore
$$
\sum_{n=0}^{\infty} \cos (2n+1)x
= \cos x + \cos 3x + \cos 5x + \cdots \\
= (\cos x + \cos 2x + \cos 3x + \cdots) - (\cos 2x + \cos 4x + \cos 6x + \cdots) \\
= \left( \frac{\pi}{2} \delta(x) - \frac12 \right) - \left( \frac{\pi}{4} \delta(x) - \frac12 \right)
= \frac{\pi}{4} \delta(x)
$$
Thus, for $x \neq 0$ we have $\sum_{n=0}^{\infty} \cos (2n+1)x = 0.$
