# myplex authentication help/examples?

**URL:** <https://forums.plex.tv/t/myplex-authentication-help-examples/18769>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [June 25, 2012, 9:54pm UTC](https://forums.plex.tv/t/myplex-authentication-help-examples/18769 "2012-06-25T21:54:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hippojay](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hippojay/32/41_2.png) [@hippojay](https://forums.plex.tv/u/hippojay)\
**Post date:** [June 25, 2012, 9:54pm UTC](https://forums.plex.tv/t/myplex-authentication-help-examples/18769/1 "2012-06-25T21:54:52Z")

</div>

python
Guys,  
  
Does anyone have a working example of how to authenticate against the myplex API in python?  
  
I've tried a number of different ways, but keep getting back a HTTP error code of 422 (Unprocessable Entity). I'm mainly using urllib2, but also tried httplib without success.  
  
I'm attempting a POST against https://my.plexapp.com/users/sign\_in.xml using basic Authentication with my working userid/password.  
  
Thanks

---

<div class="post-metadata">

**Author:** ![hippojay](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hippojay/32/41_2.png) [@hippojay](https://forums.plex.tv/u/hippojay)\
**Post date:** [June 26, 2012, 12:01pm UTC](https://forums.plex.tv/t/myplex-authentication-help-examples/18769/2 "2012-06-26T12:01:52Z")

</div>

Got it, didn’t realise that you have to send the Plex client header as part of the initial request:

```auto

<br />
import urllib2<br />
import base64<br />
<br />
username = "bingo"<br />
password = "fatpants"<br />
<br />
request = urllib2.Request("https://my.plexapp.com/users/sign_in.xml","")<br />
base64string = base64.encodestring('%s:%s' % (username, password)).replace('
', '')<br />
request.add_header("Authorization", "Basic %s" % base64string)<br />
request.add_header("X-Plex-Client-Identifier", "sausages")<br />
result = urllib2.urlopen(request)<br />
print result.read()<br />

```

---

<div class="post-metadata">

**Author:** ![elan](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/elan/32/5_2.png) [@elan](https://forums.plex.tv/u/elan)\
**Post date:** [June 27, 2012, 11:36pm UTC](https://forums.plex.tv/t/myplex-authentication-help-examples/18769/3 "2012-06-27T23:36:54Z")

</div>

You beat me to it 🙂

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 10:01pm UTC](https://forums.plex.tv/t/myplex-authentication-help-examples/18769/4 "2019-12-20T22:01:44Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
