Soundcloud API upload stopped working - soundcloud

I've run the following code for over a year and it suddenly stopped working. It has worked until 5/19/2016, and it started failing on 5/31/2016.
import soundcloud
client = soundcloud.Client(access_token=params['token'])
track_uri = client.get('/tracks/' + str(track_id)).uri # This works
client.put(track_uri, track=track) # This fails
It gives me the following traceback:
Traceback (most recent call last):
File "./tools/upload_track.py", line 56, in <module>
client.put(track_uri, track=track)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/soundcloud/client.py", line 133, in _request
return wrapped_resource(make_request(method, url, kwargs))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/soundcloud/request.py", line 148, in make_request
result.raise_for_status()
File "/Library/Python/2.7/site-packages/requests/models.py", line 844, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.soundcloud.com/tracks/266983865
It turns out that despite the error my track is uploaded to Soundcloud anyway. Unfortunately I can't ignore the error because in some cases I post new tracks (client.post instead of client.put), and I need to know the track_id's in order to put them into a playlist.
Some of the things I've tried, where I got the same error:
I tried uploading to a different Soundcloud account
I tried creating the client object with client_id, client_secret, username, and password instead of access_token
I double checked that the token is valid, that it's different every time I run the code, and that the client.get call fails when I use the wrong token

Related

How to fix the error in python pybliometrics.scopus.exception.Scopus401Error?

I'm new to pybliometrics. I opened the python pybliometrics documentation and ran this example:
from pybliometrics.scopus import AffiliationSearch
query = "AFFIL(Max Planck Institute for Innovation and Competition Munich)"
s = AffiliationSearch(query)
print(s)
But it throws a pybliometrics.scopus.exception.Scopus401Error error.
Traceback (most recent call last):
File "C:/Users/Professional/PycharmProjects/firstScopus/main.py", line 3, in <module>
s = AffiliationSearch(query)
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\affiliation_search.py", line 106, in __init__
Search.__init__(self, query=query, api="AffiliationSearch",
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\superclasses\search.py", line 76, in __init__
Base.__init__(self, qfile, refresh, params=params, url=SEARCH_URL[api],
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\superclasses\base.py", line 70, in __init__
resp = get_content(url, params, *args, **kwds)
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\utils\get_content.py", line 88, in get_content
raise errors[resp.status_code](reason)
pybliometrics.scopus.exception.Scopus401Error
Process finished with exit code 1
As I understand it, I need to specify the API keys. How to do it?
You're right, according to https://pybliometrics.readthedocs.io/en/stable/access.html#error-messages 401 is most likely due to a missing key.
As the documentation on the configuration states, pybliometrics starts a process in the beginning to create the config. It asks for the API keys, and more. It seems you skipped this.
To manually create the config, go to your home directory (~/ on *nix systems) and create the folder .scopus (the dot is important). In there, create the file config.ini with a normal text editor. It needs to have at least those two sections, Directories and Authentication as shown on the documentation on the configuration.
Or simply reinstall pybliometrics and don't skip the set-up prompt in the beginning.

Sending HTTP post requests

I am using a micropython firmware version esp8266-20190125-v1.10.bin for esp8266mod. I accessed REPL prompt via a wired connection using picocom and connected the device to my home wifi. I was trying to send some HTTP post requests using urequests.
import urequests
response = urequests.post('http://lakshmick.pythonanywhere.com/savedata', data = {'string': 'posting from micropython'})
I got some error like this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "urequests.py", line 115, in post
File "urequests.py", line 100, in request
File "urequests.py", line 79, in request
TypeError: object with buffer protocol required
Does it require any additional configuration procedures before importing urequests?
You need to serialize the data into a string before sending it:
myPostedData = {'YYYY' : 100}
res = urequest.post('https://XXX.amazonaws.com/XXX/XXX', data=json.dumps(myPostedData))
jsonresults = json.loads(res.content)

Smartsheet Python SDK Copy Workspace Fails

I am trying to copy a workspace to get around the 100 object limit.
Here's my code:
def rg_copy_workspace(workspace_id, new_ws_name, api_token, debug=False):
import smartsheet
smartsheet = smartsheet.Smartsheet(api_token)
smartsheet.errors_as_exceptions(True)
new_workspace = smartsheet.Workspaces.copy_workspace(
workspace_id,
smartsheet.models.ContainerDestination({
'new_name': new_ws_name
})
)
just like the example in the Python SDK.
I am testing on a workspace with a small number of objects (I started with only one Sheet)
I'm getting an error on the folder_obj. I have tried it with and without a folder, and when I have a folder with and without contents.
rg_copy_workspace(workspace_id, new_ws_name)
Traceback (most recent call last):
File "", line 1, in
rg_copy_workspace(workspace_id, new_ws_name)
File "", line 15, in rg_copy_workspace
'new_name': new_ws_name
File "(path-deleted)\workspaces.py", line 80, in copy_workspace
folder_obj = Folder({
File "(path-deleted)\smartsheet.py", line 210, in request
"""
File "(path-deleted)\smartsheet.py", line 278, in request_with_retry
if 200 <= response.status_code <= 299:
File "(path-deleted)\smartsheet.py", line 244, in _request
native = res.native(expected)
UnexpectedRequestError: (, None)
What am I doing wrong? I don't know how the code makes it to line 80 of workspaces.py.
I updated to latest version of SDK this morning (after receiving the error)
Craig
Reputation won't let me comment.
Your code seemed to execute fine for me on the updated 1.3 SDK.
The traceback locations look to lineup with sources from roughly a year ago, but linecache is pulling from the new source to build the traceback (smartsheet.py, line 210 is actually in a comment, so it's definitely not right). I'm not sure what all the situations are that could account for this but I'd guess there are compiled bytecode (.pyc) files somewhere that are stale.
Can you share a DEBUG level log near the relevant failure so that I can see what the API request looks like?

train.py error in ibm watson retrieve and rank service setup

I'm following the retrieve and rank tutorial and everything is good until the train.py script - I get error "ValueError: No JSON object could be decoded"
my command line with masked creds:
python ./train.py -u "zzzz":"ssss" -i /Users/nik/Downloads/cranfield_gt.csv -c "zzzz" -x example_collection -n "example_ranker"
result:
Input file is /Users/nik/Downloads/cranfield_gt.csv
Solr cluster is zzzz
Solr collection is example_collection
Ranker name is example_ranker
Rows per query 10
Generating training data...
Command:
curl -k -s -u zzzz:ssss -d "q=what similarity laws must be obeyed when constructing aeroelastic models of heated high speed aircraft.&gt=184,3,29,3,31,3,12,2,51,2,102,2,13,1,14,1,15,1,57,3,378,3,859,3,185,2,30,2,37,2,52,1,142,1,195,1,875,3,56,2,66,2,95,2,462,1,497,2,858,2,876,2,879,2,880,2,486,0&generateHeader=true&rows=10&returnRSInput=true&wt=json" "https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/solr_clusters/zzzz/solr/example_collection/fcselect"
Response:
Traceback (most recent call last):
File "./train.py", line 88, in <module>
parsed_json = json.loads(output)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Ideas why I get this error and most of all how to resolve it?
Thanks,
Nik
OK this is one of those late night experiences .. I was convinced that I did uploaded my cranfield_data.json file, but checking it today showed me that I didn't.
Runnig the script today to upload it again and seeing the confirmation was the key.
After that I've repeated the train.py and everything worked!
I hope this helps someone else too.
BTW just before uploading the first time I've tried to update and recompile curl. It seems that I did not configure it to use https and I guess I did not payed attention when I executed the curl to upload cranfield_data.json the first time.
Today I saw the error "protocol "https" not supported" and this helped me understand what happened before. Restoring the original curl on my mac resolved the issue.

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. tastypie

Continuing my search for an answer to get oauth2.0 to work on pythonanywhere.
i am following this tutorial: http://ianalexandr.com/blog/building-a-true-oauth-20-api-with-django-and-tasty-pie.html
im using django 1.6 : https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango
when i get to this line of codes:
from provider.oauth2.models import Client
# from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
User = get_user_model()
u = User.objects.get(id=1)
c = Client(user=u, name="mysite client", client_type=1, url="http://pythonx00x.pythonanywhere.com")
c.save()
c.client_id
'd63f53a7a6cceba04db5'
c.client_secret
'afe899288b9ac4127d57f2f12ac5a49d839364dc'
it seems that i got an error at line:
User = get_user_model()
and it raise an error:
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
here is the full stack trace:
Traceback (most recent call last):
File "addClient.py", line 9, in <module>
User = get_user_model()
File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 136, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/apps/registry.py", line 200, in get_model
self.check_models_ready()
File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/apps/registry.py", line 132, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I can't seem to find out how to get the models load.
if I'm getting the idea right.
I think you may not be using the version of Django that you think you are. AppRegistryNotReady was introduced in Django 1.7. I would guess that, if you pinned your DJango version to 1.6, your code would work.