ImportError: No module named 'requests.packages.urllib3.contrib.appengine' - python

I can't run my script I'm using python3 and I install pyrebase and his dependencies
I got this below exception when I try to run my script on linux ubuntu
Traceback (most recent call last):
File "scrapping2fb.py", line 9, in <module>
import pyrebase
File "/usr/local/lib/python3.4/dist-packages/pyrebase/__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "/usr/local/lib/python3.4/dist-packages/pyrebase/pyrebase.py", line 19, in <module>
from requests.packages.urllib3.contrib.appengine import is_appengine_sandbox
Can some one help me
Thank you
The script that i try to run
from urllib.request import urlopen ,URLError,HTTPError,Request
from socket import timeout
from bs4 import BeautifulSoup
from time import sleep
import mysql.connector
from datetime import datetime
import pyrebase
def is_exist_firebase_db_AR(siteName,title):#(siteName,title):
global config
global email
global password
firebase = pyrebase.initialize_app(config)
db=firebase.database()
auth = firebase.auth()
user = auth.sign_in_with_email_and_password(email, password)
all_items = db.child("items_ar").get(user['idToken'])
if(all_items.each() is not None):
for item in all_items.each():
if(siteName in item.val().get("nomSite") and title in item.val().get("titre")):
return 1
return 0

This is a problem with the pyrebase package.
Since commit 8e17600ef60de4faf632acb55d15cb3c178de9bb which went into v2.16.0, requests no longer bundle urllib3.
The package pyrebase is relying on this implementation detail, and, like all things that rely on implementation details eventually do, was broken.

Related

AttributeError: module 'wsgi' has no attribute 'application'

app.py file code:
import webbrowser
import time
#!/usr/bin/env python
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
import certifi
import json
def get_jsonparsed_data(url):
"""
Receive the content of ``url``, parse it as JSON and return the object.
Parameters
----------
url : str
Returns
-------
dict
"""
response = urlopen(url, cafile=certifi.where())
data = response.read().decode("utf-8")
return json.loads(data)
url = ("https://financialmodelingprep.com/api/v3/quote/AAPL,FB?apikey=d099f1f81bf9a62d0f16b90c3dc3f718")
print(get_jsonparsed_data(url))
country = get_jsonparsed_data(url)
count = 0
for result in country:
if count == 0:
header = result.keys()
for head in header:
html_content = f"<div> {head} </div>"
count += 1
with open("index.html", "w") as html_file:
html_file.write(html_content)
print("Html file created successfully !!")
time.sleep(2)
webbrowser.open_new_tab("index.html")
passenger_wsgi.py file code:
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'app.py')
application = wsgi.application
Error:
Traceback (most recent call last):
File "/home/stockpee/staging/passenger_wsgi.py", line 9, in <module>
application = wsgi.application
AttributeError: module 'wsgi' has no attribute 'application'
Traceback (most recent call last):
File "/home/stockpee/staging/passenger_wsgi.py", line 9, in <module>
application = wsgi.application
AttributeError: module 'wsgi' has no attribute 'application'
Hi,
Everyone, I am new in Python. I have develop a basic application on my local machine. But when I deployed it on A2Host hosting server. I am facing above error when I run my application in web browser.
Is anyone help me to fix above issue. I will be very thankful for that person.
I will applogize in advance for my brief answer. But it has to do with the fact that you have not established a whisky app.
You need to make sure in your main application file app.py you establish your application.
def app(environ, start_response):
pprint("whoo hooo. ")
I hope this helps.

Unable to import facebook SDK for Targetting search API

I was trying to use Targetting search API from facebook business SDK API.
ImportError: No module named facebookads.adobjects.targetingsearch
Using Python 2.7.12
~
Was trying to execute this piece of code:
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
'q': 'un',
'type': 'adgeolocation',
'location_types': ['country'],
}
resp = TargetingSearch.search(params=params)
print(resp)
Actual result :
Traceback (most recent call last):
File "test.py", line 2, in <module>
from facebookads.adobjects.targetingsearch import TargetingSearch
ImportError: No module named facebookads.adobjects.targetingsearch
Facebook Marketing API docs a bit outdated. You should replace the import from:
from facebookads.adobjects.targetingsearch import TargetingSearch
to:
from facebook_business.adobjects.targetingsearch import TargetingSearch
Also, before requesting targeting data, you should initialize FacebookAdsApi with your generated access token:
from facebook_business.api import FacebookAdsApi
FacebookAdsApi.init(access_token=access_token)

I cannot import a module and I don't know why Python: ImportError: Cannot import name X

I'm having the following error when I try to run a Flask app:
File "/home/patterson/Documentos/CPFL/cpfl/computer.py", line 12, in <module>
from cpfl.cpfl import sendmail
ImportError: cannot import name 'sendmail'
sendmail is a function I'm trying to import from the cpfl.py module which is a flask app.
cpfl.py:
...
app = Flask(__name__)
...
The structure of my project is as follows:
I have no idea why import does not work.
Could someone help-me?
Have you tried import cpfl and then when you call the method you use cpfl.sendmail?

python: called function from other file needs modules

I am calling a function from functions.py into work.py, which works fine:
from functions import get_ad_page_urls
The get_ad_page_urls function makes use of a.o. the requests module.
Now, wether or not I import the requests module into work.py, when I run the called function in work.py, it gives an error: NameError: name 'requests' is not defined.
I have defined get_ad_page_urls in functions.py including the module, like so,
def get_ad_page_urls():
import requests
<rest of function>
or excluding the module, like so,
import requests
def get_ad_page_urls():
<rest of function>
but it doesn't matter, the NameError persists.
How should I write the function such that when I call the function in work.py everything works fine?
Traceback:
get_ad_page_urls(page_root_url)
Traceback (most recent call last):
File "<ipython-input-253-ac55b8b1e24c>", line 1, in <module>
get_ad_page_urls(page_root_url)
File "/Users/myname/Documents/RentIndicator/Python Code/idealista_functions.py", line 35, in get_ad_page_urls
NameError: name 'requests' is not defined
functions.py
import requests
import bs4
import re
from bs4 import BeautifulSoup
def get_ad_page_urls(page_root_url):
response = requests.get(page_root_url)
soup = bs4.BeautifulSoup(response.text)
container=soup.find("div",{"class":"items-container"})
return [link.get("href") for link in container.findAll("a", href=re.compile("^(/inmueble/)((?!:).)*$"))]
work.py
import requests
import bs4
import re
from bs4 import BeautifulSoup
from functions import get_ad_page_urls
city='Valencia'
lcity=city.lower()
root_url = 'https://www.idealista.com'
house_href='/alquiler-habitacion/'
page_root_url = root_url +house_href +lcity+ '-' + lcity + '/'
get_ad_page_urls(page_root_url)
Mine works perfectly fine running on python 3.4.4
functions.py
import requests
def get_ad_page_urls():
return requests.get("https://www.google.com")
work.py
from functions import get_ad_page_urls
print(get_ad_page_urls())
# outputs <Response [200]>
Make sure they are in the same directory. You might be using two different python versions and one of them doesn't have requests?

Jira-Python - jira.client import error

I was installing jira-python like written in the docs
$ pip install jira-python
but after installation I try to run the example:
from jira.client import JIRA
options = {
'server': 'https://jira.atlassian.com'
}
jira = JIRA(options)
projects = jira.projects()
keys = sorted([project.key for project in projects])[2:5]
issue = jira.issue('JRA-1330')
import re
atl_comments = [comment for comment in issue.fields.comment.comments
if re.search(r'#atlassian.com$', comment.author.emailAddress)]
jira.add_comment(issue, 'Comment text')
issue.update(summary="I'm different!", description='Changed the summary to be different.')
issue.delete()
getting the following error:
**Traceback (most recent call last):
File "jira.py", line 4, in <module>
from jira.client import JIRA
File "/home/ubuntu/jira.py", line 4, in <module>
from jira.client import JIRA
ImportError: No module named client**
Any idea about the problem here? I tried it also on an Amazon instance, but same problem...
seems like the reason was that my test file was named jira.py :) thanks for your help Inbar!

Categories

Resources