I need to set a custom timeout to the following client or configuration:
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.client.ClientConfiguration;
Client client = WebClient.client(api);
ClientConfiguration config = WebClient.getConfig(client);
I read this and especially this but I can't find those suggested property or methods in my objects. I'd rather not change the objects type.
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
Client client = WebClient.client(api);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(0);
httpClientPolicy.setReceiveTimeout(0);
http.setClient(httpClientPolicy);
I needed to add this to the code I posted before:
HTTPConduit conduit = config.getHttpConduit();
conduit.getClient().setReceiveTimeout(150000);
//conduit.getClient().setConnectionTimeout(120000);
And it worked. I just needed to set the receive timeout, but the connection timeout setting works too.
Related
I'm trying to update the stream every 15 minutes to change its rules.
As far as I understand it is impossible to update the filter rules in real time. So I try to stop the stream and then start it again.
class MyStream(tweepy.StreamingClient):
def disconnect(self):
self.running=False
print('stop stream)
stream = MyStream(bearer_token=bearer_token, wait_on_rate_limit=True)
stream.disconnect()
But it doesn't work. Streaming continues to work.
Can you please tell me how to reallocate what I have in mind?
update
I try to add a rule to the stream, then wait 10 seconds and add another one. But it doesn't work. Can you please tell me what the problem is and how to fix it?
import telebot
import tweepy
import time
bot = telebot.TeleBot()
api_key =
api_key_secret =
bearer_token =
access_token =
access_token_secret =
client = tweepy.Client(bearer_token, api_key, api_key_secret, access_token, access_token_secret)
auth = tweepy.OAuth1UserHandler(api_key, api_key_secret, access_token, access_token_secret)
api = tweepy.API(auth)
class MyStream(tweepy.StreamingClient):
def on_connect(self):
print('Connected')
def on_response(self, response):
print(response)
stream = MyStream(bearer_token=bearer_token, wait_on_rate_limit=True)
rules = ['book', 'tree', 'word']
#create the stream
for rule in rules:
stream.add_rules(tweepy.StreamRule(rule))
print('Showing the rule')
print(stream.get_rules().data)
stream.filter(tweet_fields=["referenced_tweets"])
# this part of the code no longer works.
print('sleep 10 sec')
time.sleep(10)
# this part not working too
print('Final Streaming Rules:')
print(stream.get_rules().data)
In Twitter API v2 (Tweepy using the tweepy.client interface and StreamingClient object) the stream does not need to disconnect in order to update the rules, you do that by adding rules via StreamingClient.add_rules(). Docs:
StreamingClient.add_rules() can be used to add rules before using StreamingClient.filter() to connect to and run a filtered stream:
streaming_client.add_rules(tweepy.StreamRule("Tweepy"))
streaming_client.filter()
StreamingClient.get_rules() can be used to retrieve existing rules
and
StreamingClient.delete_rules() can be used to delete rules.
So I have an app that makes frequent requests to various endpoints on our API, and every request pretty much has the same custom headers sent with it. I'd like to know if there is a way to globally set custom header using NSURLSessionConfiguration, and if so...what is the syntax in Swift and where would I put it? AppDelegate? I've done some searching and can't seem to find a good example of this. Is it a bad practice? Not doable?
EDIT:
I'm using Alamofire for request/response, so I need something that sets them globally so that that library (and others that happen to use NSURLSession) will send the headers along by default.
We have this documented right in the README.
var defaultHeaders = Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders ?? [:]
defaultHeaders["DNT"] = "1 (Do Not Track Enabled)"
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.HTTPAdditionalHeaders = defaultHeaders
let manager = Alamofire.Manager(configuration: configuration)
Then you need to use the new manager instead of the global Alamofire singleton.
manager.request(.GET, "https://httpbin.org/get")
.responseJSON { _, _, result in
debugPrint(result)
}
This will attach the DNT header to every request that is sent through this manager instance.
Each Manager instance has its own internal NSURLSession which also has its own configuration. Therefore, this override only works for this Manager instance. If you need these headers on a different Manager instance, you'll have to set it up the same way.
I am trying to authenticate my credentials to access the GMail API. Previously I did this using the run() method from OAuth2, and the code credentials = tools.run(flow, STORAGE, http=http) but this is now a deprecated method. I am now using the run_flow() method to authenticate my credentials.
import httplib2
import argparse
from apiclient import errors
from apiclient.discovery import build
from oauth2client import tools
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
CLIENT_SECRET_FILE = 'your_client_secret.json'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.modify'
STORAGE = Storage('gmail.storage')
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()
credentials = STORAGE.get()there are credentials, no reauth is needed
#parser = argparse.ArgumentParser(parents=[tools.argparser])
#flags = parser.parse_args() #Put your arguments in the parenthesis
if credentials is None or credentials.access_token_expired:
credentials = run(flow, STORAGE, http=http)
#credentials = tools.run_flow(flow, STORAGE, flags, http=http)
http = credentials.authorize(http)
gmail_service = build('gmail', 'v1', http=http)
The commented lines are the code that uses run_flow() and not run().
The commented out code gives me the error: run.py: error: unrecognized arguments: AdminTests, AdminTests is not an argument I give to Python.
And when I change the arguments parsed to flags = parser.parse_args(['--noauth_local_webserver']) I get no error, but nothing happens.
Which flag should I use to simulate the run() as closesly as possible and how should I parse it?
Edit: When using the run() method to authenticate my credentials the URL accessed is:
http://localhost:8080/?code=4/myuniqueID (missing my unique ID in the example)
what you need to do for this is pass an empty list of args to the argparser like this
flags = tools.argparser.parse_args(args=[])
credentials = tools.run_flow(flow, storage, flags)
After comparing your code to the source code of OAuth's run and run_flow, it turns out that there is a significant difference between whether you include the http argument.
So,
tools.run(flow, STORAGE, http=http)
can be simulated with,
tools.run_flow(flow, STORAGE, flags, http=http)
but you have,
tools.run_flow(flow, STORAGE, flags)
I am using nusoap in my PHP application when calling a .net webservice.
The issue is, in some cases .net web service is taking more than actual time for some request, so I want to increase the time my SOAP call waits for the response.
Is there any function or any way that I can keep nusoap call waiting until I get a response from the webservice.
Thanks,
Rama
Nusoap default timeout is 30 secs.
Increase Response timeout to solve this problem.
// creates an instance of the SOAP client object
$client = new nusoap_client($create_url, true);
// creates a proxy so that WSDL methods can be accessed directly
$proxy = $client -> getProxy();
// Set timeouts, nusoap default is 30
$client->timeout = 0;
$client->response_timeout = 100;
Note : This settings also didn't work for some time. So i directly went to nusoap.php file and changed $response_timeout = 120. By default this value set to 30 secs.
It is solved now :)
References : Time out settings - Second reference
When you create the istance of the nusoap_client try
$client = new nusoap_client($$creat_url, true,false,false,false,false,0,300);
where all the false parameters default to false,
0 is the timeout and 300 is the response_timeout
Thanks
In case of a system error from the GradesManagementService, the returned response object is null, but the response header includes the diagnostic information. What class do I use to get this information?
Here is my code:
GradesManagementServiceV10 port = service.getGradesManagementServiceV10();
GetGradeValuesByOrgUnitRequest r = new GetGradeValuesByOrgUnitRequest(); GetGradeValuesByOrgUnitResponse resp = new GetGradeValuesByOrgUnitResponse(); WSBindingProvider bp = (WSBindingProvider)port; bp.setOutboundHeaders( Headers.create(formatSOAPHeader())); ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getUrl());
resp = port.getGradeValuesByOrgUnit(r); // the response is null. <------ How do I see what the error is?
In your service object (in the above code snippet that would be port, the object of the Web service proxy class GradesManagementServiceV10), ResponseHeader property would contain such information (this property's type is ResponseHeaderInfo).
If you are doing new development with Desire2Learn I would also suggest that you look at the Valence REST/JSON API. New features and new API calls are going to show up in that system http://docs.valence.desire2learn.com/ (it is always deployed, the docs are open, etc.)