# 'unknown encoding: idna' on socket.connect()

**URL:** <https://forums.digi.com/t/unknown-encoding-idna-on-socket-connect/2756>\
**Category:** Python\
**Created:** [November 18, 2010, 2:46am UTC](https://forums.digi.com/t/unknown-encoding-idna-on-socket-connect/2756 "2010-11-18T02:46:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwright](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@cwright](https://forums.digi.com/u/cwright)\
**Post date:** [November 18, 2010, 2:46am UTC](https://forums.digi.com/t/unknown-encoding-idna-on-socket-connect/2756/1 "2010-11-18T02:46:00Z")

</div>

Hi,

On a CP X4 I am running a Python routine that attempts to open a socket to port 502 on localhost (to the IA module) and read from it.

A standalone test version works fine.

Called from a larger program (which is also doing some HTTP POSTing to an external server), the same code gets an ‘unknown encoding: idna’ on socket.connect().

Appears I am sensitizing something that causes the idna encoding error.

There was a previous post by someone encountering this error using httplib. Solution was to use digi\_httplib. That doesn’t seem to be what is happening here.

Anyone seen such behavior?

Thanks,

- C

---

<div class="post-metadata">

**Author:** ![cwright](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@cwright](https://forums.digi.com/u/cwright)\
**Post date:** [November 18, 2010, 3:11am UTC](https://forums.digi.com/t/unknown-encoding-idna-on-socket-connect/2756/2 "2010-11-18T03:11:44Z")

</div>

I seem to have solved this problem. On a hunch, I checked the type of the host name being presented to the socket connect. It was unicode. I made it str, and now the socket opens without problem.

- C

---

<div class="post-metadata">

**Author:** ![jpod1313](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jpod1313](https://forums.digi.com/u/jpod1313)\
**Post date:** [November 18, 2010, 2:12pm UTC](https://forums.digi.com/t/unknown-encoding-idna-on-socket-connect/2756/3 "2010-11-18T14:12:14Z")

</div>

[http://forums.digi.com/support/forum/viewthread\_thread,8295](http://forums.digi.com/support/forum/viewthread_thread,8295)

see above --^

---

<div class="post-metadata">

**Author:** ![AuTim](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@AuTim](https://forums.digi.com/u/AuTim)\
**Post date:** [March 19, 2018, 7:57am UTC](https://forums.digi.com/t/unknown-encoding-idna-on-socket-connect/2756/4 "2018-03-19T07:57:22Z")

</div>

I believe the response has now moved to here…and thank you to all involved in solving and writing about this!  
[https://forums.digi.com/8785/problem-using-httplib-to-post-remote-server-httplib-request](https://forums.digi.com/8785/problem-using-httplib-to-post-remote-server-httplib-request)
