Simplejson decoding error only occurs when performing over two iterations

Tags: python json

I'm trying to use the names module along with a wrapper for ( for part of a project involving creating temporary email addresses. My code is as shown below and works fine unless n is greater than 2.

import names
from random import randint
from tempmail import TempMail

n = input("Please enter number of email addresses: ")
i = 0
while i < n:
    first = names.get_first_name()
    second = names.get_last_name()
    tm = TempMail(login= first + "." + second + str(randint(1,99)))
    email = tm.get_email_address()
    print email
    i = i+1

If n is greater than two the loop will execute twice then I receive the following error:

>>> runfile('/root/', wdir='/root')
Please enter number of email addresses: 3
[email protected]
[email protected]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/", line 714, in runfile
    execfile(filename, namespace)
  File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/", line 81, in execfile
    builtins.execfile(filename, *where)
  File "/root/", line 12, in <module>
    email = tm.get_email_address()
  File "/usr/local/lib/python2.7/dist-packages/", line 66, in get_email_address
    available_domains = self.available_domains
  File "/usr/local/lib/python2.7/dist-packages/", line 36, in available_domains
    domains = req.json()
  File "/usr/local/lib/python2.7/dist-packages/requests/", line 826, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python2.7/dist-packages/simplejson/", line 516, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/dist-packages/simplejson/", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python2.7/dist-packages/simplejson/", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I know this is a longshot as the tempmail module isn't widely used however I was hoping I've made a simple error elsewhere and someone could help? Thanks


Okay so I looked over your problem.

The package temp-mail seems to make a request to each time you call TempMail() to get a list of available domains.

You are encountering the API's rate limiting (in short, you are calling the API too many times in a too short window)

I added some debug to the package to see what was happening. I created a virtualenv to test your code. This makes modules that I install (temp-mail and names only local to the project and not globally installed on the system) and looked at the stacktrace. The line that calls the json part is domains = req.json(), located at /home/arch/tmp-tempmail/env/lib/python2.7/site-packages/

I then edited the file to add some prints (you have to have some notions about the request module first):

url = 'http://{0}/request/domains/format/json/'.format(
req = requests.get(url)
print req
print req.text
domains = req.json()

The output is:

Please enter number of email addresses: 3

This video can help you solving your question :)
By: admin