# Buggy code
def _send_dm(self, message=None):
    username = self.consumer_key
    password = self.consumer_secret
    dmdest = app.TWITTER_DMTO
    access_token_key = app.TWITTER_USERNAME
    access_token_secret = app.TWITTER_PASSWORD

    log.debug("Sending DM: {0} {1}", dmdest, message)

    api = twitter.Api(username, password, access_token_key, access_token_secret)

    try:
        api.PostDirectMessage(dmdest, message.encode("utf8")[:139])
    except Exception as error:
        log.error("Error Sending Tweet (DM): {!r}", error)
        return False

    return True


# Traceback (TwitterError)
2018-01-19 22:26:48 DEBUG    POSTPROCESSOR :: [bd08325] Copying file from /volume1/downloads/Arrow.S06E10.FASTSUB.VOSTFR.720p.HDTV.x264-ZT.WwW.Torrent9.pe.mkv to /volume1/video/Series/Arrow/Saison 06/Arrow - S06E10 -.mkv
2018-01-19 22:26:50 DEBUG    DAILYSEARCHER :: [bd08325] GET URL: https://cdn.pymedusa.com/sb_network_timezones/network_timezones.txt [Status: 200]
2018-01-19 22:26:50 DEBUG    DAILYSEARCHER :: [bd08325] User-Agent: Medusa/0.1.23 (Linux; 3.10.102; cbfea46e-fd59-11e7-95ca-001132557447)
2018-01-19 22:26:50 DEBUG    DAILYSEARCHER :: [bd08325] Finished updating network timezones
2018-01-19 22:26:52 INFO     SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Beginning daily search for new episodes
2018-01-19 22:26:52 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from Les 100
2018-01-19 22:26:52 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from Marvel - Les Agents du S.H.I.E.L.D.
2018-01-19 22:26:52 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from X-Files : Aux frontières du réel
2018-01-19 22:26:52 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from Dragon Ball Super
2018-01-19 22:26:52 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from The Big Bang Theory
2018-01-19 22:26:52 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for The Big Bang Theory S11E14. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:52 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Looking up XEM scene mapping for show ID 80379 on TVDBv2
2018-01-19 22:26:54 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] GET URL: http://thexem.de/map/havemap?origin=tvdb [Status: 200]
2018-01-19 22:26:54 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] User-Agent: Medusa/0.1.23 (Linux; 3.10.102; cbfea46e-fd59-11e7-95ca-001132557447)
2018-01-19 22:26:54 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] No XEM data for show ID 80379 on TVDBv2
2018-01-19 22:26:54 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from Top Gear
2018-01-19 22:26:54 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Top Gear S24E01. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:54 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Looking up XEM scene mapping for show ID 74608 on TVDBv2
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] GET URL: http://thexem.de/map/havemap?origin=tvdb [Status: 200]
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] User-Agent: Medusa/0.1.23 (Linux; 3.10.102; cbfea46e-fd59-11e7-95ca-001132557447)
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] No XEM data for show ID 74608 on TVDBv2
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Top Gear S24E02. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Top Gear S24E03. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Top Gear S24E04. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Top Gear S24E05. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Top Gear S24E06. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Top Gear S24E07. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from Flash (2014)
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Searching for Flash (2014) S04E10. Reason: Status is WANTED. Searching episode
2018-01-19 22:26:55 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Seeing if we need anything from Arrow
2018-01-19 22:26:55 INFO     SEARCHQUEUE-DAILY-SEARCH :: [bd08325] Using daily search providers
2018-01-19 22:26:56 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Updating providers cache
2018-01-19 22:26:56 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Search mode: RSS
2018-01-19 22:26:56 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] GET URL: http://www.torrents9.pe/torrents_series.html,trie-date-d [Status: 301]
2018-01-19 22:26:57 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] User-Agent: Medusa/0.1.23 (Linux; 3.10.102; cbfea46e-fd59-11e7-95ca-001132557447)
2018-01-19 22:26:57 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] GET URL: http://www.torrent9.bz/torrents_series.html,trie-date-d [Status: 200]
2018-01-19 22:26:57 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] User-Agent: Medusa/0.1.23 (Linux; 3.10.102; cbfea46e-fd59-11e7-95ca-001132557447)
2018-01-19 22:27:00 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Grey's.Anatomy.S14E09.VOSTFR.HDTV.x264 to a series in your database. Parser result: title: Grey's Anatomy, season: 14, episode: [9], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.0992348194122, total_time: 0.492743968964, absolute_episode: [], quality: SDTV
2018-01-19 22:27:00 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Supernatural.S13E10.VOSTFR.HDTV.x264 to a series in your database. Parser result: title: Supernatural, season: 13, episode: [10], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.0982909202576, total_time: 0.490228891373, absolute_episode: [], quality: SDTV
2018-01-19 22:27:01 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Using cached parse result for Arrow.S06E10.VOSTFR.HDTV.x264
2018-01-19 22:27:01 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Updating RSS item: Arrow.S06E10.VOSTFR.HDTV.x264 to cache: torrent9
2018-01-19 22:27:01 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Using cached parse result for Arrow.S06E10.VOSTFR.BluRay.720p.HDTV.x264
2018-01-19 22:27:01 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Updating RSS item: Arrow.S06E10.VOSTFR.BluRay.720p.HDTV.x264 to cache: torrent9
2018-01-19 22:27:01 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Cardinal.S02E03.FRENCH.HDTV.x264 to a series in your database. Parser result: title: Cardinal, season: 2, episode: [3], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.0911409854889, total_time: 0.521023988724, absolute_episode: [], quality: SDTV
2018-01-19 22:27:02 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Van.Helsing.S02E03.FRENCH.HDTV.x264 to a series in your database. Parser result: title: Van Helsing, season: 2, episode: [3], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.103337049484, total_time: 0.482490062714, absolute_episode: [], quality: SDTV
2018-01-19 22:27:03 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Van.Helsing.S02E02.FRENCH.HDTV.x264 to a series in your database. Parser result: title: Van Helsing, season: 2, episode: [2], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.101418018341, total_time: 0.486056089401, absolute_episode: [], quality: SDTV
2018-01-19 22:27:03 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Van.Helsing.S02E01.FRENCH.HDTV.x264 to a series in your database. Parser result: title: Van Helsing, season: 2, episode: [1], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.103456020355, total_time: 0.502243041992, absolute_episode: [], quality: SDTV
2018-01-19 22:27:03 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match The.Magicians.S03E02.VOSTFR.HDTV.x264 to a series in your database. Parser result: title: The Magicians, season: 3, episode: [2], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.101494073868, total_time: 0.104778051376, absolute_episode: [], quality: SDTV
2018-01-19 22:27:04 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Esprits.criminels.(Criminal.Minds).S13E12.VOSTFR.x264 to a series in your database. Parser result: title: Esprits criminels, release_group: Criminal, season: 13, episode: [12], subtitle_language: fr, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.108685970306, total_time: 0.601166009903, absolute_episode: [], quality: Unknown
2018-01-19 22:27:05 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match How.To.Get.Away.With.Murder.S04E09.VOSTFR.HDTV.x264 to a series in your database. Parser result: title: How To Get Away With Murder, season: 4, episode: [9], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.101109981537, total_time: 0.506964921951, absolute_episode: [], quality: SDTV
2018-01-19 22:27:06 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match The.Blacklist.S05E11.VOSTFR.HDTV.x264 to a series in your database. Parser result: title: The Blacklist, season: 5, episode: [11], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.100611925125, total_time: 0.103746891022, absolute_episode: [], quality: SDTV
2018-01-19 22:27:06 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match American.Crime.Story.S02E01.VOSTFR.HDTV.x264 to a series in your database. Parser result: title: American Crime Story, season: 2, episode: [1], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.109596967697, total_time: 0.112880945206, absolute_episode: [], quality: SDTV
2018-01-19 22:27:06 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match South.Park.S19E04.FRENCH.HDTV.x264 to a series in your database. Parser result: title: South Park, season: 19, episode: [4], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.0921561717987, total_time: 0.492634057999, absolute_episode: [], quality: SDTV
2018-01-19 22:27:06 DEBUG    POSTPROCESSOR :: [bd08325] Setting permissions for /volume1/video/Series/Arrow/Saison 06/Arrow - S06E10 -.mkv to 438 as parent directory has 511
2018-01-19 22:27:07 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match South.Park.S19E03.FRENCH.HDTV.x264 to a series in your database. Parser result: title: South Park, season: 19, episode: [3], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.0863740444183, total_time: 0.419268131256, absolute_episode: [], quality: SDTV
2018-01-19 22:27:07 DEBUG    POSTPROCESSOR :: [bd08325] Transaction with 1 queries executed
2018-01-19 22:27:07 DEBUG    POSTPROCESSOR :: [bd08325] 257655: Setter sets location to /volume1/video/Series/Arrow/Saison 06/Arrow - S06E10 -.mkv
2018-01-19 22:27:07 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match South.Park.S19E02.FRENCH.HDTV.x264 to a series in your database. Parser result: title: South Park, season: 19, episode: [2], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.085067987442, total_time: 0.423039913177, absolute_episode: [], quality: SDTV
2018-01-19 22:27:07 DEBUG    POSTPROCESSOR :: [bd08325] Transaction with 1 queries executed
2018-01-19 22:27:08 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match South.Park.S19E01.FRENCH.HDTV.x264 to a series in your database. Parser result: title: South Park, season: 19, episode: [1], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.0816819667816, total_time: 0.543137073517, absolute_episode: [], quality: SDTV
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] Matched release /volume1/video/Series/Arrow/Saison 06/Arrow - S06E10 - to a series in your database: Arrow
2018-01-19 22:27:08 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Matched release X-Files.S11E03.VOSTFR.HDTV.x264 to a series in your database: X-Files : Aux frontières du réel
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] Parsed /volume1/video/Series/Arrow/Saison 06/Arrow - S06E10 - into title: Arrow, season: 6, episode: [10], type: episode, parsing_time: 0.288975000381, total_time: 0.289508104324, absolute_episode: [], quality: Unknown
2018-01-19 22:27:08 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Parsed X-Files.S11E03.VOSTFR.HDTV.x264 into title: X-Files, season: 11, episode: [3], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.147799015045, total_time: 0.148844957352, absolute_episode: [], quality: SDTV
2018-01-19 22:27:08 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Updating RSS item: X-Files.S11E03.VOSTFR.HDTV.x264 to cache: torrent9
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] Matched release Arrow.S06E10.FASTSUB.VOSTFR.720p.HDTV.x264-ZT.WwW.Torrent9.pe to a series in your database: Arrow
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] Parsed Arrow.S06E10.FASTSUB.VOSTFR.720p.HDTV.x264-ZT.WwW.Torrent9.pe into title: Arrow, season: 6, episode: [10], other: Fastsub, subtitle_language: fr, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: ZT.WwW.Torrent9, type: episode, parsing_time: 0.128906011581, total_time: 0.129073143005, absolute_episode: [], quality: 720p HDTV
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] Found codec for Arrow 
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] 257655: Formatting pattern: %SN - %Sx%0E - %EN - %QN -> Arrow - 6x10 -  - 720p HDTV
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] Notification for NMJ scan update not enabled, skipping this notification
2018-01-19 22:27:08 DEBUG    POSTPROCESSOR :: [bd08325] Sending DM: plsgard Medusa: Download Finished: Arrow - 6x10 -  - 720p HDTV
2018-01-19 22:27:09 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Black.Lightning.S01E01.VOSTFR.HDTV.x264 to a series in your database. Parser result: title: Black Lightning, season: 1, episode: [1], subtitle_language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.145395040512, total_time: 0.50969004631, absolute_episode: [], quality: SDTV
2018-01-19 22:27:09 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Vikings.S05E09.FRENCH.HDTV.x264 to a series in your database. Parser result: title: Vikings, season: 5, episode: [9], language: fr, format: HDTV, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.0819940567017, total_time: 0.419661045074, absolute_episode: [], quality: SDTV
2018-01-19 22:27:10 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrent9] :: [bd08325] Unable to match Vikings.S05E09.FRENCH.BluRay.720p.HDTV.x264 to a series in your database. Parser result: title: Vikings, season: 5, episode: [9], language: fr, format: BluRay, screen_size: 720p, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.108393907547, total_time: 0.441797018051, absolute_episode: [], quality: 720p BluRay
2018-01-19 22:27:10 ERROR    POSTPROCESSOR :: [bd08325] Error Sending Tweet (DM): TwitterError([{u'message': u'Recipient (user, screen name, or id) parameter is missing.', u'code': 38}],)
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/notifiers/tweet.py", line 136, in _send_dm
    api.PostDirectMessage(dmdest, message.encode('utf8')[:139])
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/lib/pythontwitter/__init__.py", line 3608, in PostDirectMessage
    data = self._ParseAndCheckTwitter(json)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/lib/pythontwitter/__init__.py", line 4410, in _ParseAndCheckTwitter
    self._CheckForTwitterError(data)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/lib/pythontwitter/__init__.py", line 4435, in _CheckForTwitterError
    raise TwitterError(data['errors'])
TwitterError: [{u'message': u'Recipient (user, screen name, or id) parameter is missing.', u'code': 38}]

# Fixed code
def _send_dm(self, message=None):
    username = self.consumer_key
    password = self.consumer_secret
    dmdest = app.TWITTER_DMTO
    access_token_key = app.TWITTER_USERNAME
    access_token_secret = app.TWITTER_PASSWORD

    log.debug("Sending DM: {0} {1}", dmdest, message)

    api = twitter.Api(username, password, access_token_key, access_token_secret)

    try:
        api.PostDirectMessage(message.encode("utf8")[:139], screen_name=dmdest)
    except Exception as error:
        log.error("Error Sending Tweet (DM): {!r}", error)
        return False

    return True