Looking for some help with Google App Engine. Below is the offending part of my code:
from __future__ import print_function
import webapp2
import jinja2
import csv
import os
from collections import namedtuple
from httplib2 import Http
from googleapiclient.discovery import build
from oauth2client import file, client, tools
import datetime
##code to do stuff
Where I'm running into trouble is with the "from httplib2 import Http" line. I'm getting the following error:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/c3b7fd7c606f3aa7/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/c3b7fd7c606f3aa7/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/c3b7fd7c606f3aa7/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/k~fraseline2019/20181014t160622.413269158822473824/main.py", line 10, in <module>
from httplib2 import Http
File "/base/data/home/apps/k~fraseline2019/20181014t160622.413269158822473824/lib/httplib2/__init__.py", line 382
print('%s:' % h, end=' ', file=self._fp)
^
SyntaxError: invalid syntax
I've got the httplib2 module files in my app directory. I've been googling around but nobody seems to have had this issue - can someone help?
THANK YOU!
Please read about MCVEs. It would appear that the MCVE for this issue is one line:
from httplib2 import Http
I believe your issue is that your httplib2 module lacks the needed future import.
from __future__ import print_function
Future imports only apply to the module in which they appear. Without it, in 2.7, one gets the traceback you got.
>>> print(1, 2, end='')
File "<stdin>", line 1
print(1, 2, end='')
^
SyntaxError: invalid syntax
Related
I've recently had a problem with (i think) the os module in python:
Traceback (most recent call last):
File "main.py", line 9, in <module>
api = getApi(os.environ['consumer_key'], os.environ['consumer_secret'], os.environ['access_token_key'], os.environ['access_token_secret'])
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\os.py", line 681, in __getitem__
raise KeyError(key) from None
KeyError: 'consumer_key'
my code of main.py is:
from config import getApi
import os
import sys
import time
print()
api = getApi(os.environ['consumer_key'], os.environ['consumer_secret'], os.environ['access_token_key'], os.environ['access_token_secret'])
my code of config.py is
import twitter
import os
def getApi(consumer_key, consumer_secret, access_token_key, access_token_secret):
return twitter.Api(consumer_key='*********',
consumer_secret='*********',
access_token_key='*********',
access_token_secret='*********')
Send tweets with the postUpdate is possible if I write the keys in the main.py but when I put the keys in the config.py, it don't works
Can anyone help me please ?
It's not an error with the os module, the keys simply aren't in the enviroment. If you're using a .env file you should use a module like dotenv to load the file.
im creating a packet capture program that will flash LEDs on a map depending on where the packet came from.
for locating the country the ip is in ive decided to use ipinfo.io
downloaded with command pip install ipinfo
however my program doesnt get past the import ipinfo line
i get ImportError: cannot import name abstractmethod
this program is on a raspberry pi 3 b
thanks for any help given its much appreciated.
if you need anything other information i am more than happy to provide. seen as its a lockdown in the uk ill be here basically all day everyday
edit:
so this is what i get when i run the code:WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
File "./VPCPRO.py", line 5, in <module>
import ipinfo
File "/usr/local/lib/python2.7/dist-packages/ipinfo/__init__.py", line 1, in <module>
from .handler import Handler
File "/usr/local/lib/python2.7/dist-packages/ipinfo/handler.py", line 11, in <module>
from .cache.default import DefaultCache
File "/usr/local/lib/python2.7/dist-packages/ipinfo/cache/default.py", line 5, in <module>
import cachetools
File "/usr/local/lib/python2.7/dist-packages/cachetools/__init__.py", line 3, in <module>
from .cache import Cache
File "/usr/local/lib/python2.7/dist-packages/cachetools/cache.py", line 1, in <module>
from .abc import DefaultMapping
File "/usr/local/lib/python2.7/dist-packages/cachetools/abc.py", line 1, in <module>
from abc import abstractmethod
ImportError: cannot import name abstractmethod
this is the code where the error hits
#!/usr/bin/env python
from scapy.all import *
import RPi.GPIO as GPIO
import time
import ipinfo
access_token = 'dadadadheudhq'(not the actual token)
GPIO.setmode(GPIO.BOARD)
LATCH = 12
CLK = 13
dataBit = 11
handler = ipinfo.getHandler(access_token)
okay so i figured out that i need to run this in python 3 for the error not to show however this means that scapy now will not run so. i guess ill have to make a new file for ipinfo and use it in the main file
New to programming and followed this course: https://www.youtube.com/watch?v=4F2m91eKmts&feature=emb_logo
When things went to Webscraping, got errors:
Code says:
import requests
from bs4 import BeautifulSoup
page = requests.get('https://forecast.weather.gov/MapClick.php?lat=34.05349000000007&lon=-118.24531999999999')
soup = BeautifulSoup(page.content, 'html.parser')
print(soup.find_all('a'))
Return is:
File "/Users/.../python/cleverprogrammer/webscraping.py", line 1, in
import requests File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/init.py",
line 112, in
from . import utils File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/utils.py",
line 26, in
from ._internal_utils import to_native_string File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/_internal_utils.py",
line 11, in
from .compat import is_py2, builtin_str, str File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/compat.py",
line 59, in
from http import cookiejar as cookielib File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/cookiejar.py",
line 39, in
from calendar import timegm ImportError: cannot import name 'timegm' from 'calendar'
(/Users/.../python/cleverprogrammer/calendar.py)
Is there some problem with the way Requests are installed? Maybe use of pipenv is not the correct way?
And why does it call for calendar.py file and 'timegm'? Calendar.py is different file from the same course, in same folder.
What are the steps, that I can take, to get rid of these messages and get working Requests?
Thanks in advance.
I am having a bizarre problem in which Eclipse is raising an error for the source code of a python Lib package. I am using Python 3.7.1.
The relevant line is:
import urllib.request.urlopen as uReq
I don't believe the python interpreter I'm using is relevant to this particular problem. Nevertheless, here is the code for it. (I know, it's probably horrendous. If you know a better way to do this, please kindly point me in the right direction; this is my first time using jython and I'm sure it shows.)
interpreter = new PythonInterpreter();
interpreter.exec("import sys");
interpreter.exec("import os");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\src\\python')");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\Lib')");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\Lib\\site-packages')");
interpreter.exec("print(sys.path[0])");
interpreter.exec("from myscraper import validateUrl");
The error:
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\...\ThreadTracker\src\python\myscraper.py", line 6, in <module>
import urllib.request.urlopen as uReq
SyntaxError: ("mismatched input ',' expecting NAME",
('C:\\Users\\...\\ThreadTracker\\Lib\\urllib\\request.py', 140, 13, '
*, cafile=None, capath=None, cadefault=False, context=None):\n'))
Which seems to be having a problem with this line of code from the source file:
def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
*, cafile=None, capath=None, cadefault=False, context=None):
I saw on another post that urllib3 could be used as well, so I tried:
from urllib3 import request as uReq
But this came up with its own error:
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Christina\ThreadTracker\src\python\myscraper.py", line 6, in <module>
from urllib3 import request as uReq
File "C:\Users\Christina\ThreadTracker\Lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\Christina\ThreadTracker\Lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
SyntaxError: ("no viable alternative at input '='", ('C:\\Users\\Christina\\ThreadTracker\\Lib\\logging\\__init__.py', 261, 55, ' method_name, "method:", err, file=sys.stderr)\n'))
I'm extremely confused as to why I'm getting errors from the source code... And I've been having a heck of a time just trying to get the java-python integration to work.
I have problems when try to import pywhois module, i can import my own module but still have troubles when import pywhois. I moved the pywhois folder in my project folder domain, the screentshot is below:
This is the import and calling statment below:
import part:
from pywhois import *
calling part:
w = whois('hackbo.com')
self.response.out.write(w)
The problems is it will always throw a http 500 error, error text is below:
Traceback (most recent call last):
File "/home/li/Desktop/google_appengine/google/appengine/ext/webapp/__init__.py", line 700, in __call__
handler.get(*groups)
File "/home/li/Desktop/google_appengine/domain/main.py", line 43, in get
w = whois('hackbo.com')
File "pywhois/__init__.py", line 12, in whois
text = nic_client.whois_lookup(None, domain, 0)
File "pywhois/whois.py", line 157, in whois_lookup
result = self.whois(query_arg, nichost, flags)
File "pywhois/whois.py", line 100, in whois
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: 'module' object has no attribute 'socket'
What is this error means? why i could import my own module but can not import pywhois?
Google App Engine doesn't support the socket module, which pywhois uses. It allows you to import socket, but it's an empty module.
import whois
site = input ("Enter Site : ")
n = whois.whois (site)
print (n)
this is best whois
Enjoy that, easy.