错误:“ python setup.py egg_info”失败,错误代码为1

时间:2018-11-25 17:21:08

标签: python django django-models django-rest-framework

  

尝试安装unirest时,命令“ python setup.py egg_info”失败,错误代码为1

运行命令pip install unirest以在我的views.py中使用unirest后,出现此错误。 我正在尝试在运行此命令的项目中使用汽油价格api

(geo) ABHISHEKs-MacBook-Air:map abksharma$ pip install unirest
Collecting unirest
 Using cached 
https://files.pythonhosted.org/packages/92/da/2149cbd7a8c78f8b76b377379c1bda64ec36cc13315d55f6f7de6d094ac5/Unirest-1.1.7.tar.gz
Collecting poster>=0.8.1 (from unirest)
Using cached
https://files.pythonhosted.org/packages/9f/dc/0683a458d21c3d561ab2f71b4fcdd812bf04e55c54e560b0854cea95610e/poster-0.8.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/84/0bcm7b0s6kx3496xf5ply6wh0000gn/T/pip-install-vf9ffv_s/poster/setup.py", line 2, in <module>
    import poster
  File "/private/var/folders/84/0bcm7b0s6kx3496xf5ply6wh0000gn/T/pip-install-vf9ffv_s/poster/poster/__init__.py", line 29, in <module>
    import poster.streaminghttp
  File "/private/var/folders/84/0bcm7b0s6kx3496xf5ply6wh0000gn/T/pip-install-vf9ffv_s/poster/poster/streaminghttp.py", line 61
    print "send:", repr(value)
                ^
SyntaxError: invalid syntax

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in 
/private/var/folders/84/0bcm7b0s6kx3496xf5ply6wh0000gn/T/pip- 
install-vf9ffv_s/poster/
  

views.py

from django.shortcuts import render
import requests
import unirest


def petrol(request):

    response = unirest.post("https://fuelprice.p.mashape.com/",
    headers={
    "X-Mashape-Key": "eqPyWAd3Wrmsh52b6fvG3AQ5T2ygp1KZhDfjsng702Sd7DmWN7",
    "Content-Type": "application/json",
    "Accept": "application/json"
  },
    params=("{\"fuel\":\"p\",\"state\":\"dl\"}")
)

    price = response.json()
    return render(request, 'petrol/petrol.html', {'price':price})
  

url.py

from django.urls import path
from .import views


urlpatterns = [
      path('', views.petrol, name='petrol')
]

1 个答案:

答案 0 :(得分:1)

python3不支持Unirest(至少python 3.7不支持)。而不是考虑使用requests。像这样使用它:

response = requests.post("https://fuelprice.p.mashape.com/",
    headers={
    "X-Mashape-Key": "eqPyWAd3Wrmsh52b6fvG3AQ5T2ygp1KZhDfjsng702Sd7DmWN7",
    "Content-Type": "application/json",
    "Accept": "application/json"
  },
    data={'fuel': 'p', 'state': 'dl'}
)

price = response.json()