4

I want to import requests lib (in views.py)to request some information from the other website. but there is a error like title

in ivews.py

from django.http import HttpResponse

from django.http import JsonResponse

from django.core import serializers

import requests

import json

AttributeError: cffi library '_constant_time' has no function, constant or global variable named 'spec'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:/Users/49646/Desktop/auto_order/manage.py", line 21, in
..... if not isinstance(module, ModuleType) or getattr(module, 'spec', None) is None: SystemError: returned a result with an error set

wiomoc
  • 1,069
  • 10
  • 17
y.zhang
  • 41
  • 3
  • have you solved this ? – Axil Sep 13 '19 at 04:40
  • 2
    What version of `cffi` library are you using? In Django, when I am using `bcrypt`, which also requires `cffi` lib. Then, I occurs some errors like this: ``` AttributeError: cffi library '_bcrypt' has no function, constant or global variable named '__spec__' ``` Later, I upgrade `cffi` lib from 1.11.2 to 1.13.1, then it fixes and works. – Kanaza Oct 31 '19 at 07:19
  • 3
    For anyone viewing this thread in the future, just update the ```cffi``` library to the latest version. I also faced this issue with version 1.11.2. I updated to 1.14.0 which is the latest version as of now. – Abercrombie Mar 16 '20 at 12:23

1 Answers1

0

As @John-Doe notes in the comments, upgrading cffi to latest version (now 1.14.5) fixes this exact same error. I've personally confirmed this with Django 3.x on MacOS X 10.14.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
bssrdf
  • 75
  • 9